How to write a nested multi dimensional json object

后端 未结 4 2199
离开以前
离开以前 2021-02-05 12:56

I am studying json and i was wondering if this is the right way to write a multi dimensional json object that is nested.I wrote:

var foo = {
    \"logged_in\":tr         


        
4条回答
  •  轮回少年
    2021-02-05 13:44

    That's not actually an array that you have there, that's just an object containing properties that are also objects. You're also missing a few commas so this won't even compile.

    What might be more convenient for you in this case is to use both arrays and objects to form your JSON. For Example:

     var this_json_string = {
        "state":"Ohio",
        "country":"USA",
        "products":[
            {
              "pic_id":"1500",
              "description":"Picture of a computer",
            },
    
            {
              "pic_id":"15011",
              "description":"Picture of a cpu"
            },
            {
              "pic_id":"15012",
              "description":"Picture of a cpu two"
            },
            {
              "pic_id":"1501",
              "description":"Picture of a cpu"
            }
        ]
    };
    

提交回复
热议问题