-4

I have some JSON with the following structure:

{
  0: {
    "msg_title": "question"
    "msg_id": "2716"
    "msg_body": "hi hello"
    "reply_time": "2015-12-04 06:55:16"
    "user_id": "40"
    "msg_status": "Sent"
    "total_replies": "0"
  }-
  1: {
    "msg_title": "question"
    "msg_id": "2719"
    "msg_body": "how are you"
    "reply_time": "2015-12-04 06:55:16"
    "user_id": "42"
    "msg_status": "Sent"
    "total_replies": "1"
  }
}

I have named this JSON string as getResult. I'm trying to access the elements "msg_body" , "reply_time" etc for an Array of 0: to total:

Kjuly
  • 34,476
  • 22
  • 104
  • 118
mak
  • 25
  • 6

1 Answers1

0

Initially I was Stuck but now I Got the Solution

JSONObject jObject = null;

     try {
         jObject = new JSONObject(result);
         for(int i=0;i<=jObject.length();i++)
         {
           JSONObject sys = jObject.getJSONObject(String.valueOf(i));
           reply = new ALL_REPLY_MODEL();
           reply.setLastMSG(sys.getString("msg_body"));
           reply.setSent_time(sys.getString("reply_time"));
           reply.setReceived_status(sys.getString("msg_status"));
           reply.setReceived_reply(sys.getString("total_replies"));
         }
         feedItemList.add(reply);

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
mak
  • 25
  • 6