org.json.JSONException:JSONArray [0]不是字符串Exception

时间:2016-03-23 08:41:20

标签: java arrays json

我正在尝试使用JSON字符串,我收到以下异常:

  

org.json.JSONException:JSONArray [0]不是字符串。

我的JSON就像:

{"isDataPresentForAdminPosts":true,"avgUserPostsPerDay":11.27,"avgPageResponsesPerDay":4.93,"responseTimeMaxForAdminPosts"
:"< 10 minutes","rrVsUserPostsData":[[169,43.79,0]],"dailyResponded":[3,8,2,14,13,1,1,4,0,2,0,3,0,0,23
],"responseTimeNoOfAdminPosts":[9,0,0,0,0,0,1,0],"generalRR":{"unRespondedByAdminCount":95,"postedByUsersCount"
:169,"respondedRate":43.79,"unRespondedRate":56.21,"respondedByAdminCount":74},"dailyResponseRate":[33
.33,47.06,33.33,77.78,56.52,100,100,50,0,18.18,0,20,0,0,47.92],"responseTimeMaxForUserPosts":"< 10 minutes"
,"isDataPresentForUserPosts":true,"categories":["2016-03-07","2016-03-08","2016-03-09","2016-03-10","2016-03-11"
,"2016-03-12","2016-03-13","2016-03-14","2016-03-15","2016-03-16","2016-03-17","2016-03-18","2016-03-19"
,"2016-03-20","2016-03-21"],"dailyUnresponded":[6,9,4,4,10,0,0,4,4,9,8,12,0,0,25],"responseTimeNoOfPosts"
:[46,16,9,2,0,1,0,0],"timeCategories":["< 10 minutes","10-30 minutes","30-90 minutes","1.5-6 hours","6-12
 hours","12-24 hours","24-72 hours","> 72 hours"],"avgResponseTime":"35.4 minutes"}

我这样操纵:

 IRNameValueBean bean = null;
    ArrayList<IRNameValueBean> rowObjects = new ArrayList<IRNameValueBean>();

        for (int i = 0; i < json.getJSONArray("dailyResponseRate").length(); i++)
                    {
                        bean = new IRNameValueBean();
        //Here Getting Execption
                        bean.setDate(json.getJSONArray("categories").getString(i));
    bean.setDailyResponseRate(json.getJSONArray("dailyResponseRate").getString(i));

                        rowObjects.add(bean);
                    }

1 个答案:

答案 0 :(得分:0)

你的JsonArray看起来是由双打

组成的
"dailyResponseRate":[33,.33,47.06,33.33,77. ...

使用此

bean.setDailyResponseRate(String.valueOf(json.getJSONArray("dailyResponseRate").getDouble(i)));