JSONObject quotesObject = new JSONObject(responseStr);
Log.e("leb","4");
//get it as array
JSONArray projects = quotesObject.getJSONArray("project");
我從我的服務器獲得了Json。 而這些是我的錯誤信息:爲什麼不能將JSONObject轉換爲JSONArray
12-19 11:56:17.314: W/System.err(456): org.json.JSONException: Value {"category":"1","Body":"eeee","Price":"110.0","ID":"1","NowPrice":"10.0","idRef":"1","user":"1","Title":"I"} at project of type org.json.JSONObject cannot be converted to JSONArray
12-19 11:56:17.374: W/System.err(456): at org.json.JSON.typeMismatch(JSON.java:96)
12-19 11:56:17.374: W/System.err(456): at org.json.JSONObject.getJSONArray(JSONObject.java:548)
12-19 11:56:17.413: W/System.err(456): at com.supinfo.sup.rest.ProjectRestDao$RestTaskGetAll.doInBackground(ProjectRestDao.java:197)
12-19 11:56:17.434: W/System.err(456): at com.supinfo.sup.rest.ProjectRestDao$RestTaskGetAll.doInBackground(ProjectRestDao.java:1)
12-19 11:56:17.434: W/System.err(456): at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-19 11:56:17.434: W/System.err(456): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-19 11:56:17.434: W/System.err(456): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-19 11:56:17.434: W/System.err(456): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-19 11:56:17.434: W/System.err(456): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-19 11:56:17.434: W/System.err(456): at java.lang.Thread.run(Thread.java:1096)
因爲這裏顯示的json不是數組。 – Nfear
這個JSON表示不是JSON數組的JSON對象! – Pavlos
服務器響應中沒有JSON數組。 –