[英]Trouble parsing multi-level JSON
I have a chunk of JSON which looks something like:我有一大块 JSON 看起来像:
{
"map": [
[
"zimbraFeatureCalendarUpsellEnabled",
"FALSE"
],
[
"zimbraPrefCalendarDayHourStart",
"8"
],
[
"zimbraFeatureOptionsEnabled",
"TRUE"
],
[
"zimbraAttachmentsViewInHtmlOnly",
"FALSE"
]
]
}
(and so on; there's 200+ entries) (等等;有 200 多个条目)
I need to be able to pick out individual key/value pairs from the JSON response, either with jQuery or plain old Javascript.我需要能够从 JSON 响应中挑选出单独的键/值对,使用 jQuery 或普通的旧 Javascript。 I haven't been able to figure out how to address a specific key, though.
不过,我无法弄清楚如何解决特定的键。 Any ideas?
有任何想法吗?
Instead of using arrays, you could use an object:您可以使用 object,而不是使用 arrays:
{
map : {
"zimbraFeatureCalendarUpsellEnabled" : "FALSE",
"zimbraPrefCalendarDayHourStart" : "8",
"zimbraFeatureOptionsEnabled" : "TRUE",
"zimbraAttachmentsViewInHtmlOnly" : "FALSE"
}
}
and then to access it:然后访问它:
myJSONObject.map.zimbraFeatureCalendarUpsellEnabled;
What you've described is a single level object, with a whole bunch of nested arrays so accessing will be你所描述的是一个单级 object,有一大堆嵌套的 arrays 所以访问将是
myObject.map[entryNumber][0 or 1] // 0 == key, 1 == value
You probably want something akin to this (unless you're working with existing API or some such):您可能想要类似的东西(除非您正在使用现有的 API 或类似的东西):
{
"map": {
"zimbraFeatureCalendarUpsellEnabled": "FALSE",
"zimbraPrefCalendarDayHourStart": "8",
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.