81,120
社区成员
发帖
与我相关
我的任务
分享
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"-8℃","temp2":"4℃","weather":"晴","img1":"n0.gif","img2":"d0.gif","ptime":"18:00"}}
public void getJSONObject(){
JSONObject node = JSONObject.fromObject("{'weatherinfo':{'city':'北京','cityid':'101010100','temp1':'-8℃','temp2':'4℃','weather':'晴','img1':'n0'}}");
List<Object> nodes = new ArrayList<Object>();
JSONArray jsons = JSONArray.fromObject(node.get("weatherinfo"));
for (Object o : jsons)
{
JSONObject jsonNode = JSONObject.fromObject(o);
List<Object> treeNodes = new ArrayList<Object>();
treeNodes.add(jsonNode.getString("city"));
treeNodes.add(jsonNode.getString("cityid"));
treeNodes.add(jsonNode.getString("temp1"));
treeNodes.add(jsonNode.getString("temp2"));
//...
nodes.add(treeNodes);
}
System.out.println(nodes);
}