文字列からJSONArray
を作成中にJSONException
に向いています。 JSON Validatorを使用してWebサービスから応答文字列を検証しました。ここJSONArrayを作成中のJava JSONException
はコードです:
json = new JSONObject();
content = recieveData(json.toString(), m_sTimeTableUrl + sPGId);
if (content != null){
Log.d(TAG, "got content:"+content);
try {
JSONArray jArray2 = new JSONArray(content); //THE EXCEPTION FIRES HERE!
Log.i(TAG, "Number of entries " + jArray2.length());
Happening pHappening = null;
ArrayList<Happening> pResult = new ArrayList<Happening>();
for(int i = 0; i < jArray2.length(); i++){
pHappening = new Happening();
JSONObject jObject = jArray2.getJSONObject(i);
pHappening.setEndtime(new Time(jObject.getInt("EndMinute")));
pHappening.setDocent(jObject.getString("Lecturer"));
pHappening.setRoom(jObject.getString("Room"));
pHappening.setStartTime(new Time(jObject.getInt("StartMinute")));
pHappening.setName(jObject.getString("Title"));
pHappening.setDayOfWeek(jObject.getInt("Weekday"));
pResult.add(pHappening);
}
//java.util.Arrays.sort(pResult);
return pResult;
}catch (JSONException e) {
Log.e(TAG, e.toString());
}
、これが私のコンテンツ文字列がどのように見えるかです:
いくつかの助けを楽しみ{ "Happenings" : [ { "EndMinute" : 570,
"Lecturer" : "Prof. Dr. Christian Schrödter",
"OrgLecturId" : 10181,
"Room" : "KC112",
"StartMinute" : 480,
"Title" : "Physik 1 (310321) ",
"Weekday" : 0
},
{ "EndMinute" : 675,
"Lecturer" : "Prof. Dr.-Ing. Norbert Wellerdick",
"OrgLecturId" : 1750,
"Room" : "KD010",
"StartMinute" : 585,
"Title" : "TM 1 (310341) ",
"Weekday" : 0
},
{ "EndMinute" : 780,
"Lecturer" : "Prof. Dr. Christian Schrödter",
"OrgLecturId" : 10181,
"Room" : "KC112",
"StartMinute" : 690,
"Title" : "Physik 1 (310321) ",
"Weekday" : 0
},
{ "EndMinute" : 930,
"Lecturer" : "Prof. Dr. Christian Schrödter; Dipl.-Ing. (FH) Bernd Bleyel",
"OrgLecturId" : 1742,
"Room" : "KA303",
"StartMinute" : 840,
"Title" : "Info 1 (310351) ",
"Weekday" : 0
},
{ "EndMinute" : 570,
"Lecturer" : "Prof. Dr.-Ing. Hermann Lanfer",
"OrgLecturId" : 1753,
"Room" : "KC133",
"StartMinute" : 480,
"Title" : "ET 1 (310331) ",
"Weekday" : 1
},
{ "EndMinute" : 675,
"Lecturer" : "Prof. Dr. Christian Schrödter; Dipl.-Ing. (FH) Bernd Bleyel",
"OrgLecturId" : 1742,
"Room" : "KA303",
"StartMinute" : 585,
"Title" : "Info 1 (310351) ",
"Weekday" : 1
},
{ "EndMinute" : 780,
"Lecturer" : "Prof. Dr.-Ing. Axel Schenk",
"OrgLecturId" : 1812,
"Room" : "KD010",
"StartMinute" : 690,
"Title" : "Mathe 1 (310311) ",
"Weekday" : 1
},
{ "EndMinute" : 570,
"Lecturer" : "Prof. Dr. Christian Schrödter",
"OrgLecturId" : 8357,
"Room" : "KC112",
"StartMinute" : 480,
"Title" : "Info 1 (310351) ",
"Weekday" : 2
},
{ "EndMinute" : 675,
"Lecturer" : "Prof. Dr.-Ing. Hermann Lanfer",
"OrgLecturId" : 1753,
"Room" : "KC112",
"StartMinute" : 585,
"Title" : "ET 1 (310331) ",
"Weekday" : 2
},
{ "EndMinute" : 780,
"Lecturer" : "Prof. Dr.-Ing. Robert Paspa",
"OrgLecturId" : 1764,
"Room" : "KC112",
"StartMinute" : 690,
"Title" : "Konstruk.1 (310381) ",
"Weekday" : 2
},
{ "EndMinute" : 930,
"Lecturer" : "Prof. Dr.-Ing. Axel Schenk",
"OrgLecturId" : 1812,
"Room" : "KC112",
"StartMinute" : 840,
"Title" : "Mathe 1 (310311) ",
"Weekday" : 2
},
{ "EndMinute" : 570,
"Lecturer" : "Birgitta Götzelmann-Liebig",
"OrgLecturId" : 8324,
"Room" : "KC113",
"StartMinute" : 480,
"Title" : "TechEngl1 (310391) ",
"Weekday" : 3
},
{ "EndMinute" : 675,
"Lecturer" : "Birgitta Götzelmann-Liebig",
"OrgLecturId" : 8324,
"Room" : "KC113",
"StartMinute" : 585,
"Title" : "TechEngl1 (310391) ",
"Weekday" : 3
},
{ "EndMinute" : 780,
"Lecturer" : "Prof. Dr.-Ing. Hermann Lanfer",
"OrgLecturId" : 1753,
"Room" : "KD010",
"StartMinute" : 690,
"Title" : "ET 1 (310331) ",
"Weekday" : 3
},
{ "EndMinute" : 930,
"Lecturer" : "Prof. Dr.-Ing. Axel Schenk",
"OrgLecturId" : 1812,
"Room" : "KD010",
"StartMinute" : 840,
"Title" : "Mathe 1 (310311) ",
"Weekday" : 3
}
] }
!
ありがとうございます!
何が例外ですか?完全なスタックトレースしてください! –
JSONはオブジェクトであり、配列ではありません。おそらくキャスト例外 – andyb
は、logcat(そのアンドロイドアプリ)の完全なスタックトラッキーです。 –