js如何把ajax读取的json的某一个字段转化为普通数组? 10
{"records":[{"Name":"AlfredsFutterkiste","City":"Berlin","Country":"Germany"},{"Name"...
{
"records":
[
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico"
}
]
}
想把里面的Name字段里的元素转化为
["Alfreds Futterkiste","Berglunds snabbköp","Centro comercial Moctezuma"]
这样的数组 展开
"records":
[
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico"
}
]
}
想把里面的Name字段里的元素转化为
["Alfreds Futterkiste","Berglunds snabbköp","Centro comercial Moctezuma"]
这样的数组 展开
展开全部
var data = {
"records":
[
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "México D.F.",
"Country" : "Mexico"
}
]
};
var nameList = [];
for(var i = 0 ; i < data.records.length; i++ ){
nameList[nameList.length] = data.records[i].Name;
}
// nameList 就是你想要的东西
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询