json:
{
"success": 1,
"data": [
{
"data": {
"code": "1,2,3,4,5",
},
"type": "demo1",
},
{
"data": {
"code": "2,3,4,5,6",
},
"type": "demo2",
}
]
}
JS code:
onLoad:function(){
var that = this;
wx.request({
url: 'http://www.xxx.com/api.php?act=2',
header: {
'content-type': 'application/json'
},
success: function(res) {
that.setData({
codes:res.data.data[0].data.opencode.split(","),
}),
}
})
}
//As above, how can I turn the code in json into an array? I can't write the code in data[] to death. Otherwise, the previous view outputs a lot of duplicates, and I have been searching for a day but I still can’t find the answer.
Thank you guys in advance for giving me some ideas. I just learned small programs and I don’t understand many of them.
Completed, after various attempts 2333
html:
js:
Is what you ultimately want to get a data structure like this:
If so, you can try the following code: