如何在Android中正確解析此JSON文件?Android在JSONObject中解析JSONObjects
我需要讓所有的對象說塔1(這裏可能有不同數量的平日),並且在那些工作日還有不同數量的時間框架。
我已經成功地使用了一個靜態方法類似
JSONObject jArray = ja.getJSONObject("towers").getJSONObject("tower1") .getJSONObject("tuesday").getJSONObject("11:45-12:20");
然後我使用getString()方法值1的值。
但他們需要動態,因爲有很多可能性。
{
"towers": {
"tower 1": {
"tuesday": {
"07:30-11:30": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
},
"11:45-12:20": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
}
}
},
"tower 2": {
"wednesday": {
"07:15-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
},
"12:45-15:10": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
},
"15:30-17:05": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
}
},
"tuesday": {
"07:15-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
},
"12:45-15:10": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
},
"14:25-17:05": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3"
}
}
}
},
"building": {
"building 1": {
"monday": {
"07:15-12:20": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
},
"tuesday": {
"07:15-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
},
"wednesday": {
"07:15-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
},
"friday": {
"07:15-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
}
},
"building 2": {
"saturday": {
"08:05-11:00": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
}
},
"building 3": {
"monday": {
"12:45-15:10": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
},
"tuesday": {
"08:55-11:35": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
},
"15:30-17:55": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
},
"thursday": {
"07:15-09:40": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
},
"10:00-12:25": {
"value1": "test value 1",
"value2": "test value 2",
"value3": "test value 3",
"value4": "test value 4"
}
}
}
}
}
也顯示相關的部分代碼你試圖解析當前的json字符串 –
請參閱我的編輯請... – user754730
看到我的答案... –