Android create a JSON array of JSON Objects

后端 未结 4 487
一整个雨季
一整个雨季 2021-01-07 08:46

hi does anyone know how to create a Array that contains objects that in each objects contain several objects? i just can\'t seem to get my head round it

the structur

4条回答
  •  心在旅途
    2021-01-07 09:01

    Here are two pieces of JSON which fit your description which is "Array that contains objects that in each objects contain several objects". The first method uses Arrays inside Objects. The other one uses Objects in Objects.

    Method 1

    [ { "name" : "first object in array" , "inner array" : [ {  } , {  } ] }
     , { "name" : "second object in array" , "inner array" : [ {  } , {  } ] } ]
    
    
    

    To parse the above you need two nested for loops (or something recursive).

    Method 2

    [ { "name" : "first object in array" , "first inner object" : {  } , "second inner object" : {  } } ,  ] } ]
    
    
    

    The second method can be parsed with a single for loop because you know in advance the number of inner objects to expect.

    提交回复
    热议问题