简体   繁体   English

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

[英]org.json.JSONException: JSONArray[0] not a string Exception

I am trying to manupulate a JSON string, and I am getting the following exception: 我正在尝试处理JSON字符串,并且遇到以下异常:

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

My JSON is Like: 我的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"}

I am manipulating like this: 我这样操作:

 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);
                    }

Your JsonArray looks to be made out of doubles 您的JsonArray看起来是双打

"dailyResponseRate":[33,.33,47.06,33.33,77. ...

Use this 用这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM