syllablecake
syllablecake

Reputation: 13

Putting List Results into Objects

I am receiving a response from my server that looks like this:

[
    {
        "_id": "559d443abae4f14958f6a854",
        "owner": "559d4323bae4f14958f6a852",
        "__v": 0,
        "updated_at": "2015-07-08T15:39:38.370Z",
        "expiration_date": "2015-07-13T17:07:59.933Z",
        "address": "",
        "company": "",
        "problemCode": "",
        "devices": [],
        "active": true,
        "description": "",
        "ticketNumber": "",
        "coordinateY": "",
        "coordinateX": ""
    },
    {
        "_id": "559d4ffaddd30e5f585dd1cf",
        "owner": "559d4323bae4f14958f6a852",
        "__v": 0,
        "updated_at": "2015-07-08T16:29:46.087Z",
        "expiration_date": "2015-07-13T17:08:00.287Z",
        "address": "",
        "company": "",
        "problemCode": "",
        "devices": [],
        "active": true,
        "description": "",
        "ticketNumber": "",
        "coordinateY": "",
        "coordinateX": ""
    }
]

I need to be able to put these results into a RecyclerView of objects that I can edit. What is the best way to do this?

Upvotes: 0

Views: 37

Answers (2)

ThaiPD
ThaiPD

Reputation: 3761

You should create an Java class which contain the field in the response from Server and then use Gson lib to parse it. Refer this tutorial for details.

Upvotes: 0

jmateo
jmateo

Reputation: 579

I'm not going to say this is the best way to do it, but you can accomplish this by using retrofit which is what I use 90% of the time. Using retrofit, you can convert your json to POJO's automagically. Then you can use those POJO's as the data for your recyclerview. Essentially, you will have a List<MyObject> that you can pass from retrofit to the Recycler View's adapter.

Upvotes: 1

Related Questions