无法获取具有重复名称的嵌套 JSON 对象
我对 JSON 很陌生,所以以下可能是一个微不足道的问题,但我在 stackoverflow 上找不到任何类似的问题,所以:
我想获得一个嵌套的 JSON 对象,例如:pizza.topping. rating 但在访问它时说未定义,尽管可以看到评级对象...访问 Pizza.Rating 时它工作正常...这是否与对象 Pizza 中多次使用的“评级”有关?
这种情况有解决方法吗?
非常感谢您的帮助
ps:该对象看起来像这样:
jQuery16207381055671721697_1329849155553(
{"pizza":
{"Hjid":2030,
"creator":"n0rritt",
"pizzaTitle":"Fungi",
"rating":
[
{"Hjid":2032,
"creator":"n0rritt",
"ratingText":"it's delicious"}
],
"topping":
[
{"Hjid":2031,
"creator":"n0rritt",
"toppingText":"with fish",
"rating":
[
{"Hjid":2042,
"creator":"n0rritt",
"creationTime":"2012-02-21T19:08:22.896",
"ratingText":"good for your health"}
]
}
]
}
}
)
I'm quite new to JSON so the following might be a trivial problem, but I could not find any comparable question on stackoverflow, so:
I would like to get a nested JSON object like: pizza.topping.rating but when accessing it says undefined, although can see the rating object ... when accessing pizza.rating it works fine ... does it have something to do with the "rating" being used within the object pizza several times?
is there a work around for this situation?
thank you very much for your help
ps: the object looks something like this:
jQuery16207381055671721697_1329849155553(
{"pizza":
{"Hjid":2030,
"creator":"n0rritt",
"pizzaTitle":"Fungi",
"rating":
[
{"Hjid":2032,
"creator":"n0rritt",
"ratingText":"it's delicious"}
],
"topping":
[
{"Hjid":2031,
"creator":"n0rritt",
"toppingText":"with fish",
"rating":
[
{"Hjid":2042,
"creator":"n0rritt",
"creationTime":"2012-02-21T19:08:22.896",
"ratingText":"good for your health"}
]
}
]
}
}
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pizza.topping
是一个数组。因此,您必须访问数组索引。就像这样:pizza.topping[0]. rating
。那里的其余数组也是如此。
pizza.topping
is an array. Therefore you must access an array index. Like so:pizza.topping[0].rating
.The same goes for the rest of your arrays in there.