Complex JSON nesting of objects and arrays

前端 未结 5 1674
清歌不尽
清歌不尽 2020-12-23 09:51

I am having difficultly with syntax and structure of JSON objects/arrays.

{ 
  \"accounting\" : [   
                     { \"firstName\" : \"John\",  
              


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 10:01

    Make sure you follow the language definition for JSON. In your second example, the section:

    "labs":[{
        ""
    }]
    

    Is invalid since an object must be composed of zero or more key-value pairs "a" : "b", where "b" may be any valid value. Some parsers may automatically interpret { "" } to be { "" : null }, but this is not a clearly defined case.

    Also, you are using a nested array of objects [{}] quite a bit. I would only do this if:

    1. There is no good "identifier" string for each object in the array.
    2. There is some clear reason for having an array over a key-value for that entry.

提交回复
热议问题