下面是js里面的代码:
onLoad:function()
{
var that=this;
wx.request({
url: ‘https://XXXXXXXXX.duapp.com/gzh/all.php’,
data:{},
method: ‘GET’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
/* header: {
‘content-type’: ‘application/x-www-form-urlencoded; charset=UTF-8’
},*/
header: {
‘content-type’: ‘application/json’
},
success: function(res){
that.setData({oneList:res.data});
// var d = JSON.parse(res.data);
//console.log(d.result[0].branceParentName);
console.log(res.data);
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
}
————————————————————————————————————————————————————
上述程序中通过调试发现,服务器返回的res.data 是整个网页的源代码。
在浏览器地址栏 输入上面的网址 返回的数据是这样的:
[{“id”:“20”,“lei”:“22”,“user”:“/u5f97/u5230/u4e86”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:46:52”},{“id”:“21”,“lei”:“2222”,“user”:“/u8001/u5b50”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:47:56”},{“id”:“22”,“lei”:“23”,“user”:“/u5b59/u5b50”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:50:15”}]
然而 res.data 是这样的:
[{“id”:“20”,“lei”:“22”,“user”:“/u5f97/u5230/u4e86”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:46:52”},{“id”:“21”,“lei”:“2222”,“user”:“/u8001/u5b50”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:47:56”},{“id”:“22”,“lei”:“23”,“user”:“/u5b59/u5b50”,“nr”:“this id a twse”,“tel”:“113333113333”,“tm”:“2017-04-18 14:50:15”}]
————————————————————————————————————————————————————————————————
因为不是小程序需要的JSON格式,所以无法在小程序页面正常显示,好几天了没办法解决,跪求高手指点 !
网友回复:
f***:
大哥你的json api 写的有问题啊。有html包裹。api不是这样写的
C***:系统记录
爱盈利(aiyingli.com)移动互联网具影响力的盈利指导网站。定位于服务移动互联网创业者,移动盈利指导。我们的目标是让盈利目标清晰可见!降低门槛,让缺乏经验、资金有限的个人和团队获得经验和机会,提高热情,激发产品。


