我已經從URL輸出如下:爪哇JSON陣列
[ 「HANK-TPSSL4應用內」, 「acgeneral應用內」, 「acgeneral幅材」, 「achalf應用內」, 「acproduct應用內」 ]
我的Java代碼,從這個數組獲取每個對象:
BufferedReader in = new BufferedReader(new InputStreamReader((HttpURLConnection) alertHandleUrl.openConnection().getInputStream()));
String output;
while ((output = in.readLine()) != null) {
JSONArray array = new JSONArray(output);
for (int i =0; i < array.length(); i++)
JSONObject row = array.getJSONObject(i);
System.out.println(row);
}
我正的錯誤是在線程
異常 「主要」 org.json.JSONException:JSONArray [0]不是JSONObject。 在org.json.JSONArray.getJSONObject(JSONArray.java:330) 在com.ebay.sherlock.calc.AutoConfigFunc.main(AutoConfigFunc.java:70)
有人能幫助我嗎?在此先感謝
你輸出應該看起來像{」myarray「:[」abc「,」def「]}然後新的JSONObject(輸出)。 getJSONArray(「myarray」)....它應該這樣做。或者試着讓你的輸出看起來像{[「abc」,「def」]}和新的JSONArray(輸出) – 2013-04-28 03:28:08
嗨,由於我的輸出格式爲[「abc」,「def」]格式,我從這個JSON數組中獲取每個對象?謝謝.. – user2325703 2013-04-28 03:48:30