我得到了一個像這樣的JSON。這是一個很長的字符串。我只是粘貼一些部分,整個部分通過http://jsonlint.org/檢查JSON沒有錯誤。Json類型Missmatch,Android
{
"1": {
"fajr": "00:0-33",
"sunrise": "12:10",
"zuhr": "17:45",
"asr": "20:48",
"maghrib": "23:19",
"isha": "24:52"
},
"2": {
"fajr": "00:0-32",
"sunrise": "12:09",
"zuhr": "17:45",
"asr": "20:49",
"maghrib": "23:21",
"isha": "24:53"
},
"3": {
"fajr": "00:0-30",
"sunrise": "12:07",
"zuhr": "17:45",
"asr": "20:50",
"maghrib": "23:22",
"isha": "24:54"
}
}
我解析它像
HttpRequest request = HttpRequest.get(URL);
jsonData = request.body();
System.out.println(jsonData);
JSONArray jsonArray = new JSONArray(jsonData);
for (int i = 0; i <= jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
// GET PRAYER DETAILS
PrayerTime pt = new PrayerTime();
pt.setFajr(jsonObject.getString(FAJR));
pt.setSunrise(jsonObject.getString(SUNRISE));
pt.setJohr(jsonObject.getString(ZUHR));
pt.setAsar(jsonObject.getString(ASR));
pt.setMagrib(jsonObject.getString(MAGRIB));
pt.setEisha(jsonObject.getString(ISHA));
Log.e("PrayerTime", "" + pt.getSunrise());
}`
我喜歡
09-21 15:47:10.894: W/System.err(16172): org.json.JSONException: Value {"19":{"zuhr":"17:40","asr":"21:03","sunrise":"11:36","fajr":"0-1:0-59","isha":"13:17","maghrib":"23:43"},"17":{"zuhr":"17:41","asr":"21:01","sunrise":"11:40","fajr":"00:0-3","isha":"13:14","maghrib":"23:40"},"18":{"zuhr":"17:41","asr":"21:02","sunrise":"11:38","fajr":"00:0-1","isha":"13:15","maghrib":"23:42"},"15":{"zuhr":"17:42","asr":"21:00","sunrise":"11:43","fajr":"00:0-7","isha":"13:11","maghrib":"23:38"},"16":{"zuhr":"17:41","asr":"21:00","sunrise":"11:41","fajr":"00:0-5","isha":"13:12","maghrib":"23:39"},"13":{"zuhr":"17:42","asr":"20:58","sunrise":"11:47","fajr":"00:0-11","isha":"13:08","maghrib":"23:35"},"14":{"zuhr":"17:42","asr":"20:59","sunrise":"11:45","fajr":"00:0-9","isha":"13:10","maghrib":"23:36"},"11":{"zuhr":"17:43","asr":"20:56","sunrise":"11:51","fajr":"00:0-15","isha":"13:05","maghrib":"23:33"},"12":{"zuhr":"17:42","asr":"20:57","sunrise":"11:49","fajr":"00:0-13","isha":"13:07","maghrib":"23:34"},"21":{"zuhr":"17:40","asr":"21:04","sunrise":"11:32","fajr":"0-1:0-55","isha":"13:20","maghrib":"23:46"},"20":{"zuhr":"17:40","asr":"21:03","sunrise":"11:34","fajr":"0-1:0-57","isha":"13:18","maghrib":"23:44"},"22":{"zuhr":"17:40","asr":"21:05","sunrise":"11:30","fajr":"0-1:0-53","isha":"13:21","maghrib":"23:47"},"23":{"zuhr":"17:39","asr":"21:05","sunrise":"11:28","fajr":"0-1:0-51","isha":"13:22","maghrib":"23:48"},"24":{"zuhr":"17:39","asr":"21:06","sunrise":"11:26","fajr":"0-1:0-49","isha":"13:24","maghrib":"23:49"},"25":{"zuhr":"17:39","asr":"21:07","sunrise":"11:25","fajr":"0-1:0-47","isha":"13:25","maghrib":"23:51"},"26":{"zuhr":"17:38","asr":"21:07","sunrise":"11:23","fajr":"0-1:0-45","isha":"13:27","maghrib":"23:52"},"27":{"zuhr":"17:38","asr":"21:08","sunrise":"11:21","fajr":"0-1:0-42","isha":"13:28","maghrib":"23:53"},"28":{"zuhr":"17:38","asr":"21:09","sunrise":"11:19","fajr":"0-1:0-40","isha":"13:30","maghrib":"23:54"},"29":{"zuhr":"17:37","asr":"21:09","sunrise":"11:17","fajr":"0-1:0-38","isha":"13:31","maghrib":"23:56"},"3":{"zuhr":"17:45","asr":"20:50","sunrise":"12:07","fajr":"00:0-30","isha":"24:54","maghrib":"23:22"},"2":{"zuhr":"17:45","asr":"20:49","sunrise":"12:09","fajr":"00:0-32","isha":"24:53","maghrib":"23:21"},"10":{"zuhr":"17:43","asr":"20:56","sunrise":"11:53","fajr":"00:0-17","isha":"13:04","maghrib":"23:31"},"1":{"zuhr":"17:45","asr":"20:48","sunrise":"12:10","fajr":"00:0-33","isha":"24:52","maghrib":"23:19"},"30":{"zuhr":"17:37","asr":"21:10","sunrise":"11:15","fajr":"0-1:0-36","isha":"13:33","maghrib":"23:57"},"7":{"zuhr":"17:44","asr":"20:53","sunrise":"12:00","fajr":"00:0-23","isha":"13:00","maghrib":"23:27"},"6":{"zuhr":"17:44","asr":"20:52","sunrise":"12:02","fajr":"00:0-24","isha":"24:59","maghrib":"23:26"},"5":{"zuhr":"17:44","asr":"20:51","sunrise":"12:03","fajr":"00:0-26","isha":"24:57","maghrib":"23:25"},"31":{"zuhr":"17:37","asr":"21:11","sunrise":"11:13","fajr":"0-1:0-34","isha":"13:35","maghrib":"23:58"},"4":{"zuhr":"17:44","asr":"20:50","sunrise":"12:05","fajr":"00:0-28","isha":"24:56","maghrib":"23:23"},"9":{"zuhr":"17:43","asr":"20:55","sunrise":"11:54","fajr":"00:0-19","isha":"13:03","maghrib":"23:30"},"8":{"zuhr":"17:43","asr":"20:54","sunrise":"11:56","fajr":"00:0-21","isha":"13:01","maghrib":"23:29"}} of type org.json.JSONObject cannot be converted to JSONArray
09-21 15:47:10.919: W/System.err(16172): at org.json.JSON.typeMismatch(JSON.java:111)
09-21 15:47:10.919: W/System.err(16172): at org.json.JSONArray.<init>(JSONArray.java:91)
09-21 15:47:10.919: W/System.err(16172): at org.json.JSONArray.<init>(JSONArray.java:103)
我失去了一些東西的異常?
您的問題我想一個類似http://stackoverflow.com/questions/25427018/display-json-data-to-list-view – Nabin 2014-09-21 09:51:28
@Nabin不像這樣 – 2014-09-21 09:52:46