Source:
try {
JSONArray jsonArray = new JSONArray(intent.getStringExtra("chatData"));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
messagesArr = new JSONArray(item.getString("message"));
messagesObj = new JSONObject();
messagesObj.put("messages", messagesArr);
populateMessages(messagesObj);
}
} catch (Exception e) {
}
I've also attempted changing the following line with no success:
messagesArr = new JSONArray(item.getJSONObject("message"));
Any suggestions are appreciated.
Values:
item = {"message":"User has joined.","type":"agent","created":"2016-11-21 20:55:22","name":"Username"}
LogCat:
1-21 21:15:40.775 23532-23532/com.example.examplemobile W/System.err: org.json.JSONException: Value Johnny of type java.lang.String cannot be converted to JSONArray
11-21 21:15:40.775 23532-23532/com.example.examplemobile W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
11-21 21:15:40.785 23532-23532/com.example.examplemobile W/System.err: at org.json.JSONArray.<init>(JSONArray.java:96)
11-21 21:15:40.785 23532-23532/com.example.examplemobile W/System.err: at org.json.JSONArray.<init>(JSONArray.java:108)