that.setData({
goldData: res.data.result[0],
//result里多了个{}所以要标个[0]
})
1:解析这个json:http://www.intmote.com/myproject/test/new_file.json
wxml
黄金数据
|品种:{{item.variety}}
|最新价:{{item.latestpri}}
|开盘价:{{item.openpri}}
|最高价:{{item.maxpri}}
|最低价:{{item.minpri}}
|涨跌幅:{{item.limit}}
|昨收价:{{item.yespri}}
|总成交量:{{item.totalvol}}
|更新时间:{{item.time}}
--------------------------------
js
Page({
onLoad: function () {
var that = this;
wx.request({
url: 'http://www.intmote.com/myproject/test/new_file.json',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res.data)
that.setData({
goldData: res.data.result[0],
})
}
})
}
})
效果
_this.setData({
list_data: res.data.imgListData,
//res代表success函数的事件对,data是固定的,imgListData是上面json数据中imgListData
})
2:解析这个json:http://www.intmote.com/myproject/test/new_file2.json
wxml
列表测试
{{item.id}}、{{item.title}}
单价{{item.unitprice}}元/m²
{{item.city}}
{{cell.tags}}
js
Page({
/**
* 页面的初始数据
*/
data: {},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var _this = this
wx.request({
url: 'http://www.intmote.com/myproject/test/new_file2.json',//json数据地址
headers: {
'Content-Type': 'application/json'
},
success: function (res) {
//console.log(res.data.imgListData)
//console.log(res.data.imgListData[0].tag)
//将获取到的json数据,存在名字叫list_data的这个数组中
_this.setData({
list_data: res.data.imgListData,
//res代表success函数的事件对,data是固定的,imgListData是上面json数据中imgListData
})
}
})
}
})
效果
that.setData({
list: res.data,
//res代表success函数的事件对,data是固定的,list是数组
})
3:解析这个json:http://www.intmote.com/myproject/test/new_file3.json
wxml
{{item.id}}
wxss
.item-container{
border: 5px solid #ffffff;
height: 110rpx;
line-height: 110rpx;
margin-bottom:4rpx;
text-align: center;
background: #f6c8fb;
color: #ffffff;
}
js
Page({
data: {
},
onLoad: function () {
var that = this
wx.request({
url: 'http://www.intmote.com/myproject/test/new_file3.json',
headers: {
'Content-Type': 'application/json'
},
success: function (res) {
//将获取到的json数据,存在名字叫list的这个数组中
that.setData({
list: res.data,
//res代表success函数的事件对,data是固定的,list是数组
})
}
})
}
})
原文作者:祈澈姑娘 技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,爱折腾。
坚持总结工作中遇到的技术问题,坚持记录工作中所所思所见,对于博客上面有不会的问题,可以加入qq群聊来问我:473819131.
参考大神的:参考:https://blog.csdn.net/xchaha/article/details/81016375