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

时间:2021-01-12 20:22:38

I have the following json: I need to get the value of key "GlossSeeAlso" which is an array and to traverse through it. Can someone pls guide me how it can be done?

我有下面的json:我需要得到key“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 个解决方案

#1


0  

You can get the value with yourjsonelement.GlossSeeAlso and traverse through the array with:

您可以使用yourjsonelement获取该值。词汇表也和遍历数组:

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

#1


0  

You can get the value with yourjsonelement.GlossSeeAlso and traverse through the array with:

您可以使用yourjsonelement获取该值。词汇表也和遍历数组:

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