0

I have this JSON file

"Items": [
            {
                "Name": "Id",
                "Value": "102"
            },
            {
                "Name": "TypeUid",
                "Value": "333"
            },  {
                "Data": {
                    "Items": [
                        {
                            "Name": "Id",
                            "Value": "106"
                        },
                        {
                            "Name": "TypeUid",
                            "Value": "444"
                        },
                        {
                            "Name": "Uid",
                            "Value": "1322"
                        },
                        {
                            "Name": "Name",
                            "Value": "Alex"
                        }
                    ]

In this file key-value pairs are kept inside JSONObject. How i can parse this file with GSON like this?:

"Items": {
"id" = 102,
"typeId" = 333,
"name" = "Alex"}

I don't understand how i can get normal POJO objects for GSON with this kind of JSON file.

Logic
  • 2,230
  • 2
  • 24
  • 41

1 Answers1

0

You can simply create a model class to store the data like

class Items{
  String/int id;
  String/int typeId;
   .
   .
}

Then you can make a list which will hold the data like

List<Items> items = new ArrayList<>();

Then read the json string and parse it to form the list containing the data. Refer this answer to convert json to list: Link