2012-10-10 21 views
0
獲得JSON

我已經轉換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

+0

你從哪裏得到錯誤?你可以發佈完整的stacktrace嗎? – Tomer

+0

它轉換爲jsonArray – dd619

回答

0

那麼錯誤說,這一切,你實際上得到的是包含數組的對象,所以你應該做的是:

​​

和那麼你將擁有包含在這個對象中的數組。

+0

感謝您的回答時顯示錯誤。 – dd619