简体   繁体   中英

Parsing complex nested json Array / Objects in Android

We have a complex json structure which we need to parse in Android.

{
"StatusCode":0,
"StatusInfo":"Processed and Logged OK",
"Schools":[
    {
     "Id":"1",
     "Name":"School 1",
     "Class":[
        {
           "Id":"11",
           "Name":"Class 1",
           "Section":[
              {
                 "Id":"12",
                 "Name":"Section A"
              },
              {
                 "Id":"13",
                 "Name":"Section B"
              },
              {
                 "Id":"14",
                 "Name":"Section C"
              }
            ]
        },
        {
        "Id":"21",
        "Name":"Class 2",
        "Section":[
              {
                 "Id":"22",
                 "Name":"Section A"
              },
              {
                 "Id":"23",
                 "Name":"Section B"
              }
            ]

        }
        ]
    },
    {
     "Id":"5",
     "Name":"School 2",
     "Class":[
        {
           "Id":"51",
           "Name":"Class 1",
           "Section":[
              {
                 "Id":"512",
                 "Name":"Section A"
              },
              {
                 "Id":"513",
                 "Name":"Section B"
              },
              {
                 "Id":"514",
                 "Name":"Section C"
              }
            ]
        },
        {
        "Id":"52",
        "Name":"Class 2",
        "Section":[
              {
                 "Id":"522",
                 "Name":"Section A"
              },
              {
                 "Id":"523",
                 "Name":"Section B"
              }
            ]

        }
        ]
    }
]
}

I've checked various tutorials on json parsing in Android, but i got confused with this structure as it re-use the names under various Arrays. I would like to check if it would be easy to use libraries like GSON / Jackson to parse this json structure.

Also, if this structure is big, will it occupy more memory and have performance issue while parsing this structure each time to find a node?

Regards, Aravind. C

Gson is probably the best way to go. If you are unsure how to build your java classes you can easily generate the classes with that json code you have online here -> JsonGen

Reference from Gson Performance and Scalability

  • Strings: Deserialized strings of over 25MB without any problems
  • Large collections:
       o Serialized a collection of 1.4 million objects 
       o Deserialized a collection of 87,000 objects 
  • Gson 1.4 raised the deserialization limit for byte arrays and collection to over 11MB from 80KB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM