ASON Parsing and Generation
The ASON utility is similar to the JSON utility provided by JavaScript. JSON is used to serialize (via stringify) and deserialize (via parse) JavaScript objects. In contrast, ASON provides serialization and deserialization capabilities for Sendable objects. The ASON.stringify method converts an object to a string, and ASON.parse converts a string back to a Sendable object. This enables high-performance pass-by-reference of these objects between concurrent tasks.
The ASON.stringify method can also convert Map and Set objects into strings. These include Map, Set, collections.Map, collections.Set, HashMap and HashSet.
NOTE
By default, objects generated by ASON.parse are immutable Sendable objects that do not support adding or deleting properties. If the returned object needs to support adding or deleting properties, you can specify the return type as the collections.Map object.
Usage Example
Use ASON interfaces to serialize and deserialize Sendable objects.
import { ArkTSUtils, collections } from '@kit.ArkTS';
ArkTSUtils.ASON.parse("{}")
ArkTSUtils.ASON.stringify(new collections.Array(1, 2, 3))
let options2: ArkTSUtils.ASON.ParseOptions = {
bigIntMode: ArkTSUtils.ASON.BigIntMode.PARSE_AS_BIGINT,
parseReturnType: ArkTSUtils.ASON.ParseReturnType.MAP,
}
let jsonText = '{"largeNumber":112233445566778899}';
let map = ArkTSUtils.ASON.parse(jsonText, undefined, options2);
// Execution result: {"largeNumber":112233445566778899}
console.info(ArkTSUtils.ASON.stringify(map));