OpenHarmony开发者论坛

标题: map如何转json [打印本页]

作者: 润开鸿_坚果    时间: 2024-6-19 16:18
标题: map如何转json
[md]```
// map转JSON
const map = new Map([
  ['name', '坚果'],
  ['age', '18'],
  ['address', '深圳'],
]);
let jsonObject: Record<string, Object> = {};
map.forEach((value, key) => {
 if (key != undefined && value != undefined) {
   jsonObject[key] = value;
  }
})

let info :string=JSON.stringify(jsonObject)
```


monica-code-tools
[/md]




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5