1.鸿蒙系统arkts使用JSON库
JSON库中提供json数据和对象互转方式
interface JSON {
/**
* Converts a JavaScript Object Notation (JSON) string into an object.
* @param text A valid JSON string.
* @param reviver 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.
*/
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
/**
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer A function that transforms the results.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
/**
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
}
2.示例
2.1.Json文件
{
"userInfo":{
"name":"lili",
"age":30,
"address":"北京市",
"account":"ksnowlv"
},
"subscriptions":[
{
"title":"Flutter入门指南",
"subtitle":"从零开始学习Flutter",
"content":"Flutter是一种用于创建跨平台移动应用程序的开源UI工具包。",
"subscriptio

最低0.47元/天 解锁文章
1627

被折叠的 条评论
为什么被折叠?



