从服务器上获取一个json的数据 请大家看看 应该怎么解析 PS:格式什么的都对,请不要纠结于括号上或者json的格式上!保证是对的!!!! 听一个朋友说用foreach 但是不知道具体改怎么操作,有谁能指导下吗???? "taxonomy":{"1":{"weight":"0","tid":"1","v_weight_unused":"0","vid":"1","description":"","name":"name1"},
"2":{"weight":"0","tid":"2","v_weight_unused":"0","vid":"1","description":"","name":"name2"},
"3":{"weight":"0","tid":"3","v_weight_unused":"0","vid":"1","description":"","name":"name3"},
"510":{"weight":"0","tid":"510","v_weight_unused":"0","vid":"1","description":"","name":"name4"},
"4":{"weight":"0","tid":"4","v_weight_unused":"0","vid":"5","description":"","name":"name5"}}
"2":{"weight":"0","tid":"2","v_weight_unused":"0","vid":"1","description":"","name":"name2"},
"3":{"weight":"0","tid":"3","v_weight_unused":"0","vid":"1","description":"","name":"name3"},
"510":{"weight":"0","tid":"510","v_weight_unused":"0","vid":"1","description":"","name":"name4"},
"4":{"weight":"0","tid":"4","v_weight_unused":"0","vid":"5","description":"","name":"name5"}}
解决方案 »
- Android如何访问facebook
- 怎么自动适应800*480和960*540二种分辨率?
- 关于android流媒体视频的rtsp和http协议的2个问题
- 同屏中播放多个视频用videoview能实现吗?
- Android如何加载一个现成的动态库
- 网络通信 HttpURLConnection,Volley及HttpClient均不支持移动网络
- 新浪微博客户端开发中accessToken问题
- 用canvas画bitmap问题
- Android的声波通信实例中如何传输11个0~9的数字以及代码详解
- Android中设了4个按钮,却只有一个能用 求大神指点
- android2.3 如何进行串口开发 求大神
- Android源码开发中加入一键开关网络数据功能
StringBuilder jsonString = new StringBuilder();
jsonString.append("{\"taxonomy\":{\"1\":{\"weight\":\"0\",\"tid\":\"1\",\"v_weight_unused\":\"0\",\"vid\":\"1\",\"description\":\"\",\"name\":\"name1\"},");
jsonString.append("\"2\":{\"weight\":\"0\",\"tid\":\"2\",\"v_weight_unused\":\"0\",\"vid\":\"1\",\"description\":\"\",\"name\":\"name2\"},");
jsonString.append("\"3\":{\"weight\":\"0\",\"tid\":\"3\",\"v_weight_unused\":\"0\",\"vid\":\"1\",\"description\":\"\",\"name\":\"name3\"},");
jsonString.append("\"510\":{\"weight\":\"0\",\"tid\":\"510\",\"v_weight_unused\":\"0\",\"vid\":\"1\",\"description\":\"\",\"name\":\"name4\"},");
jsonString.append("\"4\":{\"weight\":\"0\",\"tid\":\"4\",\"v_weight_unused\":\"0\",\"vid\":\"5\",\"description\":\"\",\"name\":\"name5\"} }}"); JSONObject taxonomy;
taxonomy = new JSONObject(jsonString.toString());
JSONArray names = taxonomy.names();
String name;
for (int y = 0; y < names.length(); y++) {
name = (String) names.get(y);
Log.e("taxonomy " + name, ""+taxonomy.getJSONObject(name));
}
根节点为taxonomy,包含5个子节点
每个子节点包含6个属性
"taxonomy":
{
"1":
{
"weight":"0",
"tid":"1",
"v_weight_unused":"0",
"vid":"1",
"description":"",
"name":"name1"
},
"2":
{
"weight":"0",
"tid":"2",
"v_weight_unused":"0",
"vid":"1",
"description":"",
"name":"name2"
},
"3":
{
"weight":"0",
"tid":"3",
"v_weight_unused":"0",
"vid":"1",
"description":"",
"name":"name3"
},
"510":
{
"weight":"0",
"tid":"510",
"v_weight_unused":"0",
"vid":"1",
"description":"",
"name":"name4"
},
"4":
{
"weight":"0",
"tid":"4",
"v_weight_unused":"0",
"vid":"5",
"description":"",
"name":"name5"
}
}
不解释。