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.

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.