如何解析json以获取其值为数组的键?

时间:2015-09-19 10:37:59

标签: arrays json parsing key

我有以下json:我需要获取键“GlossSeeAlso”的值,这是一个数组并遍历它。有人可以指导我如何做到这一点吗?

{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"ID": "44",
"str": "SGML",
"GlossSeeAlso": [
{
"GML": "111",
"XML": "222"
},
{
"GML": "123",
"XML": "322"
}
]
},
"GlossSee": "markup"
}
}
}
}
}

1 个答案:

答案 0 :(得分:0)

您可以使用yourjsonelement.GlossSeeAlso获取值,并遍历数组:

for(var k in yourjsonelement.GlossSeeAlso) {
   //do something with array element k.GML and k.XML
}