-1

我正在编写 JSON 文件的以下代码以将其发布到我的网站

{
    fleetSubscriberId: 
        {
         subscriberId: "The subscriberId used during login",
         name: "Subscriber name",
         groupId: "Subscriber group ID",
         companyCode: "Subscriber company code"
        },
            fleetPolicySummaries: 
                [
                    {
                         policyNumber: "1234", companyCode: "456" 
                     }
                ],
        {
                "companyName": "Natural Resources Canada",
                "locations":
                [
                    {
                         "streetAddress": "580 Booth St 17th Fl Room a6",
                         "city": "Ottawa",
                         "stateOrProvince": "Ontario",
                         "country": "Canada"
                    }
                 ]
        }
}

它显示以下错误可以任何人帮助我解决这个问题

Error: Parse error on line 1:
{    fleetSubscriberId: 
-----^
Expecting 'STRING', '}', got 'undefined'
4

3 回答 3

0

检查这个。我格式化了你的 JSON。注意我添加了一个新的“其他”作为字段名称。

{
    "fleetSubscriberId": {
        "subscriberId": "The subscriberId used during login",
        "name": "Subscriber name",
        "groupId": "Subscriber group ID",
        "companyCode": "Subscriber company code"
    },
    "fleetPolicySummaries": [
        {
            "policyNumber": "1234",
            "companyCode": "456"
        }
    ],
    "other": {
        "companyName": "Natural Resources Canada",
        "locations": [
            {
                "streetAddress": "580 Booth St 17th Fl Room a6",
                "city": "Ottawa",
                "stateOrProvince": "Ontario",
                "country": "Canada"
            }
        ]
    }
}
于 2013-11-08T11:52:44.053 回答
0

字段名称是文字。

您也应该引用字段名称(例如"fleetSubscriberId":)以使其成为有效的 JSON。

于 2013-11-08T11:02:03.910 回答
-1

你可以在这里检查你的 json 是否有效。http://pro.jsonlint.com/ 您的 json 无效。

于 2013-11-08T11:18:06.383 回答