我從我在我通過服務,並以發送到我的活動Android應用程序服務器獲得一個JSONObject我轉換的JSONObject的字符串JSONException而轉換成JSONArray
String myjson= gson.toJson(object);
b.putString("json", myjson);
和字符串傳遞給我的活動在這裏我從字符串重新創建JSONObject的
Gson gson = new Gson();
JSONObject jobj = gson.fromJson(mydata, JSONObject.class);
JSONArray jarray = jobj.getJSONArray("myitems");
我的JSON是如下
{"myitems":[{"event_id":"1","title":"Music launch party at makeover","description":"Music Launch function at Makeover","store_id":"2","user_id":"1","category_id":"1","submittedby":"store","start_date":"2015-02-03 09:00:01","end_date":"2015-02-03 20:00:00","price":"1000","gallery_1":"","gallery_2":"","gallery_3":"","add_lat":"30.693771","add_lon":"76.76486","distance":"10.329089177806534"},{"event_id":"2","title":"The Bacardi party at the New year bash","description":"Altius organizes a new year bash at their Night House.","store_id":"2","user_id":"1","category_id":"3","submittedby":"user","start_date":"2015-02-05 17:08:40","end_date":"2015-02-05 22:08:48","price":"2000","gallery_1":"","gallery_2":"","gallery_3":"","add_lat":"30.69461","add_lon":"76.76176","distance":"10.575941394542852"}]}
但是我得到jsonobject jsonarray錯誤。從jsonobject獲取jsonarray的正確方式是什麼或者我在這裏做了什麼錯誤。
什麼錯誤說? – TZHX 2015-02-05 16:24:04
jsonexception .gson.internal.LinkedTreeMap無法轉換爲jsonarray – user2779311 2015-02-05 16:28:38
這裏有一些建議,我從網上搜索JSON操作,當在嵌套的對象或數組在JSON嘗試正確地使映射類,然後做你的工作。 – 2015-02-05 16:37:35