HarmonyOS 蓝牙扫描到的数据怎么转成JSON

{"deviceId":"88:68:E5:C0:92:8E","rssi":-67,"connectable":true,"data":{"0":2,"1":1,"2":5,"3":3,"4":2,"5":2,"6":166,"7":8,"8":9,"9":76,"10":83,"11":50,"12":49,"13":50,"14":45,"15":66,"16":12,"17":255,"18":18,"19":52,"20":86,"21":120,"22":1,"23":164,"24":193,"25":56,"26":59,"27":172,"28":243,"29":2,"30":10,"31":0},"deviceName":"LS212-B"} 

蓝牙扫描到的数据怎么转成JSON?

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

数据是JSON字符串类型的,下面示例是将这个字符串转换成Map:

let strParam =
  '{"deviceId":"88:68:E5:C0:92:8E","rssi":-67,"connectable":true,"data":{"0":2,"1":1,"2":5,"3":3,"4":2,"5":2,"6":166,"7":8,"8":9,"9":76,"10":83,"11":50,"12":49,"13":50,"14":45,"15":66,"16":12,"17":255,"18":18,"19":52,"20":86,"21":120,"22":1,"23":164,"24":193,"25":56,"26":59,"27":172,"28":243,"29":2,"30":10,"31":0},"deviceName":"LS212-B"}';
let obj: object = JSON.parse(strParam);
let targetMap: Map<string, string | number> = new Map<string, string | number>(Object.entries(obj));
console.log('obj = ', targetMap)
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS json数据如何转成map
1150浏览 • 1回复 待解决
HarmonyOS JSON数据怎么获取值
155浏览 • 1回复 待解决
HarmonyOS 读取本地json文件转成字符串
187浏览 • 1回复 待解决
harmonyOS 蓝牙怎么创建?
5804浏览 • 1回复 待解决
怎么监听蓝牙开启状态?
4987浏览 • 1回复 待解决
HarmonyOS BLE蓝牙发送数据量大问题
243浏览 • 1回复 待解决