我已經轉換HashMap的使用GSON以JSON和JSON字符串就像下面:誤差在分析這是從GSON
{"records":[{"three":"chingi0","two":"Marge0","five":"Bart0","four":"Maggie0","one":"Homer0"},{"three":"chingi1","two":"Marge1","five":"Bart1","four":"Maggie1","one":"Homer1"}]}
但在使用JSON解析這個字符串它給了我以下錯誤:
org.json.JSON.typeMismatch
下面是我的代碼片段
JSONArray jArray=new JSONArray(str);//str is the json string
JSONObject json_data;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
//here i am accessing the data from json string
}
我該如何解決這個問題?
這裏是我的堆棧跟蹤:
org.json.JSONException: Value {"records":[{"three":"chingi0","two":"Marge0","four":"Maggie0","five":"Bart0","one":"Homer0"},{"three":"chingi1","two":"Marge1","four":"Maggie1","five":"Bart1","one":"Homer1"}]} of type org.json.JSONObject cannot be converted to JSONArray
你從哪裏得到錯誤?你可以發佈完整的stacktrace嗎? – Tomer
它轉換爲jsonArray – dd619