我有这个 JSON
"DocumentType": {
"propertyName": "DocumentType",
"propertyType": "Text",
"propertyValue": "Fire"
},
"adsfsadf": {
"propertyName": "adsfsadf",
"propertyType": "Text",
"propertyValue": "sfsfdffsd"
}
我想搜索并检索具有 propertyName="DocumentType"
的节点?我已经尝试过了
result.get("//@propertyName='DocumentType'/..")
也尝试过
result.get("//propertyName[text()='DocumentType'/..")
并且每次都获取一个空对象。
最佳答案
尝试以下代码
JSONParser p = new JSONParser();
Map<String, Object> myMap = p.parseJSON(new InputStreamReader(YOUR JSON INPUT STREAM));
ArrayList<Map<String, String>> myList = (ArrayList<Map<String,String>>)myMap.get("DocumentType");
for (int i = 0; i < myList.size(); i++) {
Map<String, String> dtls = myList.get(i);
String prop = dtls.get("propertyName"));
}
谢谢!
关于codenameone - 如何使用 codenameone 结果从 json 中选择项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24324487/