diff --git a/api/@ohos.util.json.d.ts b/api/@ohos.util.json.d.ts index 03abf5a6a425e388b93eca2dbd55eac4f54d336a..1f01a71ebf0df01be6158b8ecc400f134a410ef6 100644 --- a/api/@ohos.util.json.d.ts +++ b/api/@ohos.util.json.d.ts @@ -25,7 +25,8 @@ * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ declare namespace json { /** @@ -38,7 +39,8 @@ declare namespace json { * @returns { Object | undefined | null } Return an Object, undefined or null value * @syscap SystemCapability.Utils.Lang * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ type Transformer = (this: Object, key: string, value: Object) => Object | undefined | null; @@ -62,6 +64,22 @@ declare namespace json { */ function parse(text: string, reviver?: Transformer, options?: ParseOptions): Object | null; + /** + * Converts a JavaScript Object Notation (JSON) string into an Object or null. + * + * @param { string } text - A valid JSON string. + * @param { Type } type - A constructor or class representing the expected type of the parsed result. + * @param { Transformer } [reviver] - A function that transforms the results. + * @param {ParseOptions} options - The config of parse. + * @returns { T | null | undefined } Return an Object, array, string, number, boolean, undefined, or null value corresponding to JSON text. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 20 + * @arkts 1.2 + */ + function parse(text: string, type: Type, reviver?: Transformer, options?: ParseOptions): T | null | undefined; + /** * Converts an ArkTS object or array into a JSON string. In the case of a container, linear containers are supported, * but non-linear containers are not. @@ -87,6 +105,22 @@ declare namespace json { */ function stringify(value: Object, replacer?: (number | string)[] | null, space?: string | number): string; + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * + * @param { NullishType } value - A JavaScript value, usually an NullishType or array. + * @param { Transformer | ((double | string)[]) | null } [replacer] - An array of strings and numbers that acts as an approved list + * for selecting the object properties that will be stringify. + * @param { string | int } [space] - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + * @returns { string } Return a JSON text. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 20 + * @arkts 1.2 + */ + function stringify(value: NullishType, replacer?: Transformer | ((double | string)[]) | null, space?: string | int): string; + /** * Converts an ArkTS object or array into a JSON string. In the case of a container, linear containers are supported, * but non-linear containers are not. @@ -121,7 +155,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ function has(obj: object, property: string): boolean; @@ -145,7 +180,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ const enum BigIntMode { /** @@ -154,7 +190,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ DEFAULT = 0, /** @@ -163,7 +200,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ PARSE_AS_BIGINT = 1, /** @@ -172,7 +210,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ ALWAYS_PARSE_AS_BIGINT = 2, } @@ -184,7 +223,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ interface ParseOptions { /** @@ -193,7 +233,8 @@ declare namespace json { * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ bigIntMode: BigIntMode; } diff --git a/kits/@kit.ArkTS.d.ets b/kits/@kit.ArkTS.d.ets index 9f99ee05bbfb57a451f7e9a23e9b579b230cfdf2..21f00f9bdf2f554d34ad4436932589b27175d6af 100644 --- a/kits/@kit.ArkTS.d.ets +++ b/kits/@kit.ArkTS.d.ets @@ -27,6 +27,7 @@ import util from '@ohos.util'; import Deque from '@ohos.util.Deque'; import LightWeightMap from '@ohos.util.LightWeightMap'; import Queue from '@ohos.util.Queue'; +import JSON from '@ohos.util.json'; import stream from '@ohos.util.stream'; import HashMap from '@ohos.util.HashMap'; import HashSet from '@ohos.util.HashSet'; @@ -44,5 +45,5 @@ import Decimal from '@arkts.math.Decimal'; export { ArrayList, Deque, HashMap, HashSet, LightWeightMap, LightWeightSet, LinkedList, List, - PlainArray, Queue, Stack, TreeMap, TreeSet, buffer, uri, url, util, stream, xml, transfer, collections, Decimal + PlainArray, Queue, Stack, TreeMap, TreeSet, buffer, uri, url, util, JSON, stream, xml, transfer, collections, Decimal };