【小程序】JSON字符串转JSON对象

如图:需获取到data中的数据

解决办法:JSON字符串转JSON对象

const data = res.data;

// 将JSON字符串转换为JSON对象
var jsonStr = data.replace(" ", "");
if (typeof jsonStr != 'object') {
   jsonStr = jsonStr.replace(/\ufeff/g, "");
   var jsonObj = JSON.parse(jsonStr);
   res.data = jsonObj;
}

console.log("code:"+res.data.code);
console.log("imageUrl"+res.data.imageUrl);

测试结果如下 

 

猜你喜欢

转载自blog.csdn.net/qq_35808136/article/details/88642879
今日推荐