How to parse the JSON response coming from server which is in this format


Ask A Question





Login To post a question

I have a JSON response coming from the server which looks like:

[
    {
        "user_id": 147,
        "ticket_ref_no": "6ef8b3be-b3b7-4ffb-b8ca-6f114d972553",
        "status": "open",
        "created_at": "2019-08-20 17:08:29",
        "updated_at": "2019-08-20 17:08:29",
        "latestMessage": [
            {
                "message": "Created New Ticket for test",
                "ticket_id": 2,
                "user_id": 147,
                "response_by_user_id": null,
                "created_at": "2019-08-20 17:08:29",
                "updated_at": "2019-08-20 17:08:29"
            }
        ]
    },
    {
        "user_id": 147,
        "ticket_ref_no": "d1c022f2-c12b-45ed-8d74-befc4896c5e2",
        "status": "open",
        "created_at": "2019-08-20 17:22:14",
        "updated_at": "2019-08-20 17:22:14",
        "latestMessage": [
            {
                "message": "Help Test",
                "ticket_id": 3,
                "user_id": 147,
                "response_by_user_id": null,
                "created_at": "2019-08-20 17:22:14",
                "updated_at": "2019-08-20 17:22:14"
            }
        ]
    }
]

I want to know how to parse this data, how can I send this data to my adapter, I’ve tried using:

for (int i = 0; i<data.size(); i++)
   dataMessage = new ArrayList<>(Arrays.asList(data.get(i).getLatestMessage()));

But it’s only passing the last message I mean dataMessage is overriding with the latest coming message but I want all the messages in dataMessage.
Can anyone have a solution? TIA

For more info please click herehttps://stackoverflow.com/q/57586127



Have a question or need a custom quote?
info@smartinfocare.com