0

How to parsing nested json with retrofit in android?

    {
    "204": {
        "input": [
            {
                "name": "nima",
                "school": "alavi",
                "age": 20,
                "scheduled": false
            } 
            }
        ],
        "output": [
            {
                "name": "amin",
                "school": "alavi",
                "age": 24,
                "scheduled": false
            }          
        ],
        "internal": [],
        "external": []
    }
   }

I want to read json file in two recycleview.

Nikunj
  • 3,937
  • 19
  • 33

2 Answers2

0

You can use Gson library to parse Json directly into your model class(Java objects). Retrofit is used for to call webservices.

immodi
  • 607
  • 1
  • 6
  • 21
  • refer [this tutorial](https://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/) – immodi Mar 29 '18 at 11:52
0
{
"204": {
    "input": [
        {
            "name": "nima",
            "school": "alavi",
            "age": 20,
            "scheduled": false
        } 
        }
    ],
    "output": [
        {
            "name": "amin",
            "school": "alavi",
            "age": 24,
            "scheduled": false
        }          
    ],
    "internal": [],
    "external": []
}
}

Your Object Class like this

public class [Object Class Name] {
    private ArrayList<Inputs> inputItems;
    private ArrayList<Outputs> outputItems;
    private ArrayList<Internals> internalItems;
    private ArrayList<Externals> externalItems;

    // Getters setters
}

public class Inputs {
    private String name;
    private String school;
    private int age;
    private boolean scheduled;

    // Getters setters
}

public class Outputs {
    private String name;
    private String school;
    private int age;
    private boolean scheduled;

    // Getters setters
}
Sabbir Ahmed
  • 351
  • 1
  • 13