-3

I have below json to populate the recyclerview item

{
"success": true,
"data": {
    "houses": [
        {
            "id": 1,
            "house_id": "HOUSEAGA00001",
            "ward_number": "23",
            "staus_id":1,
            "name_of_resident": "Melroy",
            "phone_number": "9890098900",
            "amount_due": 5000,
            "created_date": "2018-10-12T18:30:00.000Z",
            "updated_date": "2018-10-12T18:30:00.000Z"
        },
        {
            "id": 2,
            "house_id": "HOUSEAGA00002",
            "ward_number": "24",
            "staus_id":1,
            "name_of_resident": "Prajyot",
            "phone_number": "9823598235",
            "amount_due": 10000,
            "created_date": "2018-10-12T18:30:00.000Z",
            "updated_date": "2018-10-12T18:30:00.000Z"
        }
    ],
    "payment_statuses": [
        {
            "id": 1,
            "type": "Collected",
            "color_hex": "#00ff00"
        },
        {
            "id": 3,
            "type": "Owner unavailable",
            "color_hex": "#ff9900"
        },
        {
            "id": 2,
            "type": "Owner Denied",
            "color_hex": "#ff0000"
        }
    ]
},
"count": 2,
"error": []

}

I am using house array to populate recycler view item, but there is one field in item called status where I have to get status id from houses array and get it its respective type from payment_statuses array. The problem is how do I get the type from staus payment_statuses array from houses array in recycler view holder.

Aadit33
  • 192
  • 10
  • Provide code. We're not here to come up with solutions but to help you solve the problems you have with your code. – DallaRosa Oct 19 '18 at 06:15

1 Answers1

0

I think that this can be helpful: How parse JSON in Android In particular assuming that you have the entire JSON object in object:

To get a specific JSONArray:

JSONObject jObject = object.getJSONObject("data"); 
JSONArray jArray = jObject.getJSONArray("houses");

To get the items from the array

for (int i=0; i < jArray.length(); i++)
{
    try {
        JSONObject oneObject = jArray.getJSONObject(i);
        // Pulling items from the array
        int value = oneObject.getInt(
    } catch (JSONException e) {
        // Oops
    }
}

I didn't test the code, but the idea is something like this.

A. Wolf
  • 1,309
  • 17
  • 39