我有这样的 JSON 数据
{
"nodes": [
{
"node": {
"title": "Kieu Oanh",
"Image": "",
"view_node": "view",
"link": "drupal_dev/content/kieu-oanh"
}
},
{
"node": {
"title": "Kieu Oanh",
"Image": "",
"view_node": "view",
"link": "drupal_dev/content/kieu-oanh"
}
},
]
}
现在我想将其转换为
var rel_data = [{
"title": "asa",
"Image": "sasa",
"view_node": "sajsjla"
}, {
"title": "asa",
"Image": "sasa",
"view_node": "sajsjla"
}]
这是我将数据转换为 rel_data 的代码
data = data.nodes;
for (d in data) {
rel_data[d].title = data[d].node.title;
rel_data[d].image = data[d].node.Image;
}
for (d in rel_data) {
alert(rel_data[d].title);
}
但它似乎不起作用,我的代码有什么问题吗?