[
{
“3”:[
{
“hx_id”:”429″,
“hx_shi”:”3″,
“thumb_url”:”201406/floors_img/217_f_1402646629904.jpg”,
“hx_name”:”绿城金华御园高层户型图,三室两厅两卫”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”2″,
“hx_wei”:”2″
},
{
“hx_id”:”433″,
“hx_shi”:”3″,
“thumb_url”:”201406/floors_img/217_f_1402646779650.jpg”,
“hx_name”:”绿城·金华御园A-1户型,三室两厅一卫 “,
“hx_jianzhumianji”:”119″,
“hx_ting”:”2″,
“hx_wei”:”1″
}
],
“4”:[
{
“hx_id”:”388″,
“hx_shi”:”0″,
“thumb_url”:”201406/floors_img/217_f_1402642648469.jpg”,
“hx_name”:”绿城·金华御园别墅V1户型(地下层)”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”0″,
“hx_wei”:”0″
},
{
“hx_id”:”391″,
“hx_shi”:”0″,
“thumb_url”:”201406/floors_img/217_f_1402642842339.jpg”,
“hx_name”:”绿城·金华御园别墅V1户型(第一层)”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”0″,
“hx_wei”:”0″
}
]
]
这样的数据怎么样解析? 求指导 3和4不是固定的 有可能为1,2 或 5,6,7,8….
{
“3”:[
{
“hx_id”:”429″,
“hx_shi”:”3″,
“thumb_url”:”201406/floors_img/217_f_1402646629904.jpg”,
“hx_name”:”绿城金华御园高层户型图,三室两厅两卫”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”2″,
“hx_wei”:”2″
},
{
“hx_id”:”433″,
“hx_shi”:”3″,
“thumb_url”:”201406/floors_img/217_f_1402646779650.jpg”,
“hx_name”:”绿城·金华御园A-1户型,三室两厅一卫 “,
“hx_jianzhumianji”:”119″,
“hx_ting”:”2″,
“hx_wei”:”1″
}
],
“4”:[
{
“hx_id”:”388″,
“hx_shi”:”0″,
“thumb_url”:”201406/floors_img/217_f_1402642648469.jpg”,
“hx_name”:”绿城·金华御园别墅V1户型(地下层)”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”0″,
“hx_wei”:”0″
},
{
“hx_id”:”391″,
“hx_shi”:”0″,
“thumb_url”:”201406/floors_img/217_f_1402642842339.jpg”,
“hx_name”:”绿城·金华御园别墅V1户型(第一层)”,
“hx_jianzhumianji”:”不详”,
“hx_ting”:”0″,
“hx_wei”:”0″
}
]
]
这样的数据怎么样解析? 求指导 3和4不是固定的 有可能为1,2 或 5,6,7,8….
解决方案:40分
private void ParseJson() { // String json = // "{"3":"婚房","2":"学区房","1":"商场周边","7":"交通便利"," // + ""6":"包物业费","5":"采光好","4":"小户型"}"; String json = " {\n" + " "3":[\n" + " {\n" + " "hx_id":"429",\n" + " "hx_shi":"3",\n" + " "thumb_url":"201406/floors_img/217_f_1402646629904" + ".jpg",\n" + " "hx_name":"绿城金华御园高层户型图,三室两厅两卫",\n" + " "hx_jianzhumianji":"不详",\n" + " "hx_ting":"2",\n" + " "hx_wei":"2"\n" + " },\n" + " {\n" + " "hx_id":"433",\n" + " "hx_shi":"3",\n" + " "thumb_url":"201406/floors_img/217_f_1402646779650" + ".jpg",\n" + " "hx_name":"绿城·金华御园A-1户型,三室两厅一卫 ",\n" + " "hx_jianzhumianji":"119",\n" + " "hx_ting":"2",\n" + " "hx_wei":"1"\n" + " }\n" + " ],\n" + " "4":[\n" + " {\n" + " "hx_id":"388",\n" + " "hx_shi":"0",\n" + " "thumb_url":"201406/floors_img/217_f_1402642648469" + ".jpg",\n" + " "hx_name":"绿城·金华御园别墅V1户型(地下层)",\n" + " "hx_jianzhumianji":"不详",\n" + " "hx_ting":"0",\n" + " "hx_wei":"0"\n" + " },\n" + " {\n" + " "hx_id":"391",\n" + " "hx_shi":"0",\n" + " "thumb_url":"201406/floors_img/217_f_1402642842339" + ".jpg",\n" + " "hx_name":"绿城·金华御园别墅V1户型(第一层)",\n" + " "hx_jianzhumianji":"不详",\n" + " "hx_ting":"0",\n" + " "hx_wei":"0"\n" + " }\n" + " ]\n" + "}"; try { JSONObject jsonObject = new JSONObject(json); for (Iterator<String> iterator = jsonObject.keys(); iterator .hasNext();) { String key = iterator.next().toString(); JSONArray jsonArray = jsonObject.getJSONArray(key); System.out.print("key=" + key + "\n"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject2 = jsonArray.getJSONObject(i); for (Iterator<String> iterator2 = jsonObject2.keys(); iterator2 .hasNext();) { String key2 = iterator2.next().toString(); System.out.println(key2 + ":" + jsonObject2.get(key2)); } } System.out.println("\n"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }