如何在代号一中读取嵌套的JSON [英] How to read nested JSON in Codename One
本文介绍了如何在代号一中读取嵌套的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在这里按照说明进行操作:
https ://www.codenameone.com/javadoc/com/codename1/io/JSONParser.html 从json文件中检索值。
我已经设法读取json内容的顶级值-但是我看不到如何读取嵌套标签的值,例如使用此文件...
I have been following the instructions here: https://www.codenameone.com/javadoc/com/codename1/io/JSONParser.html to retrieve a value from a json file. I have managed to read the top level value of my json content - however I cannot see how to read the value of a nested tag e.g. using this file ...
{
"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.",
"GlossSeeAlso":[
"GML",
"XML"
]
},
"GlossSee":"markup"
}
}
}
}
}
请有人可以告诉我如何
谢谢
推荐答案
在基于此,您可以使用 Result
深入了解json内容:
After parsing your json data based on this, you can use Result
to read deep into the json content:
import com.codename1.processing.Result;
...
Map<String, Object> data = json.parseJSON(r);
Result result = Result.fromContent(data);
String id = result.getAsString("glossary/GlossDiv/GlossList/GlossEntry/ID");
String para = result.getAsString("glossary/GlossDiv/GlossList/GlossEntry/GlossDef/para");
这篇关于如何在代号一中读取嵌套的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文