Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Jsons

Json helper class
JSON工具类

Hierarchy

  • Jsons

Index

Methods

Static clone

  • clone<T>(obj: T): T
  • Clone json object or array or date.

    Type parameters

    • T

    Parameters

    • obj: T

    Returns T

Static equal

Static equalKeys

Static filter

  • Returns a filtered JSON.

    Parameters

    • json: JsonObject
    • fn: (this: JsonObject, value: object, key: string) => boolean

      If the function returns TRUE then save the key, otherwise remove the key.
      过滤函数。返回true表示保留该键值,false则不保留。

        • (this: JsonObject, value: object, key: string): boolean
        • Parameters

          Returns boolean

    Returns JsonObject

Static find

  • Gets value by the property path from JSON data.

    Example:

    let json = {a:{b:{c:1}}};
    Jsons.find(json, 'a.b.c'); //print 1
    

    Parameters

    • data: JsonObject

      json data

    • path: string

      the path string of property

    Returns any

Static forEach

  • forEach<T>(json: JsonObject<T>, fn: (value: T, key: string) => any, that?: any): void
  • Type parameters

    • T

    Parameters

    • json: JsonObject<T>
    • fn: (value: T, key: string) => any
        • (value: T, key: string): any
        • Parameters

          • value: T
          • key: string

          Returns any

    • Optional that: any

    Returns void

Static hasKey

  • hasKey(json: JsonObject, key: string | number): boolean
  • Parameters

    Returns boolean

Static intersect

  • Returns {json1 ^ json2}

    Parameters

    Returns {}

    • [key: string]: T

Static keys

Static minus

  • Returns {json1 - json2}

    Parameters

    Returns {}

    • [key: string]: T

Static parse

  • parse(text: string, reviver?: (key: any, value: any) => any): any
  • Converts a JSON string into a JSON object.

    Parameters

    • text: string

      A valid JSON string.

    • Optional reviver: (key: any, value: any) => any

      A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is.

        • (key: any, value: any): any
        • Parameters

          • key: any
          • value: any

          Returns any

    Returns any

Static replaceKeys

  • Returns a new json object with new key-names.
    将JSON对象中指定属性名称替换成新属性名并返回

    Parameters

    Returns JsonObject

Static some

  • some<T>(json: JsonObject<T>, fn: (value: T, key: string) => boolean, that?: any): boolean
  • Type parameters

    • T

    Parameters

    • json: JsonObject<T>
    • fn: (value: T, key: string) => boolean
        • (value: T, key: string): boolean
        • Parameters

          • value: T
          • key: string

          Returns boolean

    • Optional that: any

    Returns boolean

Static stringify

  • stringify(value: any, replacer?: (key: string, value: any) => any | (string | number)[] | null, space?: string | number): string
  • Converts a JavaScript value to a JSON string.

    Parameters

    • value: any

      A JavaScript value, usually an object or array, to be converted.

    • Optional replacer: (key: string, value: any) => any | (string | number)[] | null

      A function that transforms the results.

        • (key: string, value: any): any | (string | number)[] | null
        • Parameters

          • key: string
          • value: any

          Returns any | (string | number)[] | null

    • Optional space: string | number

      Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

    Returns string

Static union

  • Returns a newly merged JSON object and the following JSON object will deeply overwrites the previous JSON object.
    Note: the key whose value is undefined in json2 will be ignored.
    返回合并后的Json对象: 后面的JSON对象深度覆盖前面的JSON对象
    注意:Json2中值为undefined的key会被忽略。

    Parameters

    Returns JsonObject

Static values

  • Type parameters

    • T

    Parameters

    Returns T[]