我从JSON
文件中获取此对象
{
"Apple": "Red",
"Orange": "Orange",
"Guava": "Green",
}
然后我使用
将其转换为Object
var data = JSON.parse(dataFromJson);
然后输出JavaScript object
问题
是否可以访问"Apple", "Orange", "Guava"
然后将其存储到var fruits
然后"Red", "Orange","Green"
进入var Color
答案 0 :(得分:3)
您也可以这样做:
var data = JSON.parse(dataFromJson);
var fruits = [];
var colors = [];
for(var fruit in data) {
fruits.push(fruit);
colors.push(data[fruit]);
}
答案 1 :(得分:1)