我已经使用 GSON 将 Hashmap 转换为 json,json 字符串如下所示:
{"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: 值 {"records":[{"three":"chingi0","two":"Marge0","four":"Maggie0","five":"Bart0","one": "Homer0"},{"three":"chingi1","two":"Marge1","four":"Maggie1","five":"Bart1","one":"Homer1"}]} 类型org.json.JSONObject 无法转换为 JSONArray