I am working on an android project. I need help in this JSON data parsing which I am retrieving from the server:
{"item_name":["Navnita","Navnita","Navnita"],"username":["James","John","Jenny"],"review":["Its a relly nice restaurant for Vegetarians! :)","Cool!","Food is just great!"]}
I just want to populate the RecyclerView with the "username" and his "review".
Right now I am using the following code to parse the JSON data and populate an arrayList which in turn populates the RecyclerView but it gives me error(logcat below):
String result ....;
JSONObject jObject = new JSONObject(result);
JSONArray usernameJsonArray = jObject.getJSONArray("username");
JSONArray reviewJsonArray = jObject.getJSONArray("review");
for(int i=0;i<usernameJsonArray.length();i++){
String username = usernameJsonArray.getJSONObject(i).toString();
String review = reviewJsonArray.getJSONObject(i).toString();
getReviewFeedItemsArrayList.add(new GetReviewFeedItems(username,review));
}
I think that the problem is with this above code but I am not able to figure it out. Here's the logcat:
09-19 14:33:24.295 30572-30646/app.usrete.jayant.delvemitt W/System.err﹕ org.json.JSONException: Value James at 0 of type java.lang.String cannot be converted to JSONObject
09-19 14:33:24.305 30572-30646/app.usrete.jayant.delvemitt W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:100)
09-19 14:33:24.305 30572-30646/app.usrete.jayant.delvemitt W/System.err﹕ at org.json.JSONArray.getJSONObject(JSONArray.java:484)
{["item":"Nanvita", "username":"James", "review": "Best ever!"], [...], [...]}. For your question: looks like @Ravi got it!