简体   繁体   中英

What am I doing wrong with this JSON?

I have wrotten this script in JSON and I put it through JSON builder and it says on the schedule line it is expecting string. Can someone tell me what I am doing wrong?

{
    "ParentGroup": {
        "group_id": "",
        "group_name": "Group A",
        "schedule": {
            [
                "start":"9",
                "end":"10"
            ],
            [
                "start":"12",
                "end":"13"
            ]
        }

    }
}

The schedule part should be:

    "schedule": [
        {
            "start":"9",
            "end":"10"
        },
        {
            "start":"12",
            "end":"13"
        }
    ]

It is an array containing two objects, not an object containing two arrays :-)

Your schedule property is an object and thus expects property identifiers next. I think, what u mean is something like this:

    "schedule": [
        {
            "start":"9",
            "end":"10"
        },
        {
            "start":"12",
            "end":"13"
        }
    ]

In general [ ] denotes an array and as such does not need property identifiers, whereas { } denotes an object in which every property needs an id.

There are some great tools to verify json :) eg. http://jsonformatter.curiousconcept.com/#jsonformatter

Depending on what you are trying to do, here is one solution for valid json:

{
  "ParentGroup":
  {
    "group_id": "",
    "group_name": "Group A",
    "schedule":
    [
        {
            "start":"9",
            "end":"10"
        },
        {
            "start":"12",
            "end":"13"
        }
    ]
  }
}

您正在使用名称:值对填充数组,该对应该在对象中(花括号表示法)。

i believe it should be like

{
    "ParentGroup": {
        "group_id": "",
        "group_name": "Group A",
        "schedule": [
            {
                "start":"9",
                "end":"10"
            },
            {
                "start":"12",
                "end":"13"
            }
        ]

    }
}

because schedule is array of objects not object of arrays

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