中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
HarmonyOS json对象转map类型。
微信扫码分享
let map = new Map([ ['name', '张三'], ['age', '18'], ['address', 'xian'], ]); // map转json let jsonObject: Record<string, Object> = {} map.forEach((value, key) => { if (key != undefined && value != undefined) { jsonObject[key] = value; } }) let info: string = JSON.stringify(jsonObject); console.log("map转json:" + info) //json转object let jsonRecord: Record<string, Object> = JSON.parse(info) as Record<string, Object>; console.log("json转object:" + jsonRecord)