版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/haoranhaoshi/article/details/85258027
String jsonString = "{'nodeInfo':{'data1':'Root','data2':'Root data','data3':''},'childNotes':[{'nodeInfo':{'data1':'Child 1','data2':'Child 1 data','data3':'child 1 notes'},'childNotes':[{'nodeInfo':{'data1':'Child 3','data2':'Child 3 data','data3':'Child 3 notes'},'childNotes':[]}]},{'nodeInfo':{'data1':'Child 2','data2':'Child 2 data','data3':'Child 2 notes'},'childNotes':[]}]}";
JSONObject json = JSONObject.fromObject(jsonString);
String root = json.getJSONObject("nodeInfo").get("data1").toString();
Iterator<JSONObject> it = (json.getJSONArray("childNotes")).iterator();
while(it.hasNext()){
JSONObject json2 = it.next();
}
Json字符串格式化:
在线Json格式化网站,或者notepad++中装入Json Viewer插件,或者Win10中的Code Writer。
相关Jar包:
commons-beanutils-1.8.0
commons-collections-3.2.1
commons-lang-2.5
commons-logging-1.1.1
ezmorph-1.0.6
json-lib-2.4-jdk15