下面是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 是这样的:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/javascript;charset=UTF-8” />
<title>无标题文档</title>
</head>
<body>
[{“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”}]
</body>
</html>
————————————————————————————————————————————————————————————————因为不是小程序需要的JSON格式,所以无法在小程序页面正常显示,好几天了没办法解决,跪求高手指点 !