说到json,我是个菜鸟。我越用它,我开始喜欢它。我的输出看起来像这样
[
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
实际上我只列出了一种产品,但输出中列出了很多产品。我想循环浏览这个json输出并获得所有产品的类别,可用的国家和使用fbjs的价格。
我感谢任何帮助。
感谢。
答案 0 :(得分:1)
如果您的JSON是这样的,
var products = [
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
},
{
"product": {
"id": "7",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
你可以迭代:
for(var index = 0; index < products.length; index++) {
alert(products[index].product.category);
}