【小程序】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);

测试结果如下 

【小程序】JSON字符串转JSON对象_第1张图片 

 

你可能感兴趣的:(小程序)