1

所以我试图将一些 JSON 放在一起并将其解析为 jquery,但我的 JSON 语法有问题。我尝试通过验证器运行它,但它并没有真正告诉我我做错了什么。有人可以指出我的方式的错误吗?

var searchresults = [
{
    "providerlisting": [
    {
        "nametitle": "Cory M Spears, MD, FACP",
        "caretype": "Internal Medicine",
        "preferredProvider": true,
        "address1": "289 N. Highland Ave.",
        "address2": "",
        "cityStateZip": "Atlanta, GA 30306",
        "coverage": "/images/example.png",
        "status": "Out of Network",
        "psn": "",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    },
    {
        "nametitle": "Jimmy Dean, MD, FACP",
        "caretype": "External Medicine",
        "preferredProvider": false,
        "address1": "3 Piedmont Rd.",
        "address2": "",
        "cityStateZip": "Atlanta, GA 30706",
        "coverage": "/images/example2.png",
        "status": "In Network",
        "psn": "urlhere",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    },
    {
        "nametitle": "John Doe, DD, PM",
        "caretype": "Internal Medicine",
        "preferredProvider": true,
        "address1": "500 Ponce De Leon Ave",
        "address2": "Suite 5",
        "cityStateZip": "Atlanta, GA 30706",
        "coverage": "/images/example2.png",
        "status": "Out of Network",
        "psn": "urlhere",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    }]
},
{
"categories": [{
    "categoryMenu": [
        {
            "providertype": [
                {
                    "title": "Doctor",
                    "link": "#doctor",
                    "amount": "400"
                },
                 {
                     "title": "Hospital",
                     "link": "#hospital",
                     "amount": "40"
                 },
                 {
                     "title": "Urgent Care",
                     "link": "#urgentCare",
                     "amount": "37"
                 }
            ]
        },
        {
            "specialty": [
                {
                    "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "2"
                },
                {
                    "title": "Audiology",
                    "link": "#audiology",
                    "amount": "3"
                },
                {
                    "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "6"
                },
                {
                    "title": "Ambulatory Surgical Center",
                    "link": "#ambulatorySurgicalCenter",
                    "amount": "4"
                }
            ]
        },
        {
            "gender": [
                {
                    "title": "Male",
                    "link": "#male",
                    "amount": "67"
                },
                {
                    "title": "Female",
                    "link": "#female",
                    "amount": "3"
                }
            ]
        }
    }]
}];
4

4 回答 4

4

删除,每个末尾的

 "rating": "urlhere"

最后第三行有一个]缺失,下面是一个有效的 json 对象

var searchresults = [{
    "providerlisting": [{
        "nametitle": "Cory M Spears, MD, FACP",
            "caretype": "Internal Medicine",
            "preferredProvider": true,
            "address1": "289 N. Highland Ave.",
            "address2": "",
            "cityStateZip": "Atlanta, GA 30306",
            "coverage": "/images/example.png",
            "status": "Out of Network",
            "psn": "",
            "dcontact": "urlhere",
            "save": "urlhere",
            "rating": "urlhere"
    }, {
        "nametitle": "Jimmy Dean, MD, FACP",
            "caretype": "External Medicine",
            "preferredProvider": false,
            "address1": "3 Piedmont Rd.",
            "address2": "",
            "cityStateZip": "Atlanta, GA 30706",
            "coverage": "/images/example2.png",
            "status": "In Network",
            "psn": "urlhere",
            "dcontact": "urlhere",
            "save": "urlhere",
            "rating": "urlhere"
    }, {
        "nametitle": "John Doe, DD, PM",
            "caretype": "Internal Medicine",
            "preferredProvider": true,
            "address1": "500 Ponce De Leon Ave",
            "address2": "Suite 5",
            "cityStateZip": "Atlanta, GA 30706",
            "coverage": "/images/example2.png",
            "status": "Out of Network",
            "psn": "urlhere",
            "dcontact": "urlhere",
            "save": "urlhere",
            "rating": "urlhere"
    }]
}, {
    "categories": [{
        "categoryMenu": [{
            "providertype": [{
                "title": "Doctor",
                    "link": "#doctor",
                    "amount": "400"
            }, {
                "title": "Hospital",
                    "link": "#hospital",
                    "amount": "40"
            }, {
                "title": "Urgent Care",
                    "link": "#urgentCare",
                    "amount": "37"
            }]
        }, {
            "specialty": [{
                "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "2"
            }, {
                "title": "Audiology",
                    "link": "#audiology",
                    "amount": "3"
            }, {
                "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "6"
            }, {
                "title": "Ambulatory Surgical Center",
                    "link": "#ambulatorySurgicalCenter",
                    "amount": "4"
            }]
        }, {
            "gender": [{
                "title": "Male",
                    "link": "#male",
                    "amount": "67"
            }, {
                "title": "Female",
                    "link": "#female",
                    "amount": "3"
            }]
        }]
    }]
}];
于 2013-09-04T16:40:53.130 回答
0
Please find the corrected Json string

var searchresults = [
{
    "providerlisting": [
    {
        "nametitle": "Cory M Spears, MD, FACP",
        "caretype": "Internal Medicine",
        "preferredProvider": true,
        "address1": "289 N. Highland Ave.",
        "address2": "",
        "cityStateZip": "Atlanta, GA 30306",
        "coverage": "/images/example.png",
        "status": "Out of Network",
        "psn": "",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    },
    {
        "nametitle": "Jimmy Dean, MD, FACP",
        "caretype": "External Medicine",
        "preferredProvider": false,
        "address1": "3 Piedmont Rd.",
        "address2": "",
        "cityStateZip": "Atlanta, GA 30706",
        "coverage": "/images/example2.png",
        "status": "In Network",
        "psn": "urlhere",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    },
    {
        "nametitle": "John Doe, DD, PM",
        "caretype": "Internal Medicine",
        "preferredProvider": true,
        "address1": "500 Ponce De Leon Ave",
        "address2": "Suite 5",
        "cityStateZip": "Atlanta, GA 30706",
        "coverage": "/images/example2.png",
        "status": "Out of Network",
        "psn": "urlhere",
        "dcontact": "urlhere",
        "save": "urlhere",
        "rating": "urlhere",
    }]
},
{
"categories": [{
    "categoryMenu": [
        {
            "providertype": [
                {
                    "title": "Doctor",
                    "link": "#doctor",
                    "amount": "400"
                },
                 {
                     "title": "Hospital",
                     "link": "#hospital",
                     "amount": "40"
                 },
                 {
                     "title": "Urgent Care",
                     "link": "#urgentCare",
                     "amount": "37"
                 }
            ]
        },
        {
            "specialty": [
                {
                    "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "2"
                },
                {
                    "title": "Audiology",
                    "link": "#audiology",
                    "amount": "3"
                },
                {
                    "title": "Allergy and Immunology",
                    "link": "#allergyAndImmunology",
                    "amount": "6"
                },
                {
                    "title": "Ambulatory Surgical Center",
                    "link": "#ambulatorySurgicalCenter",
                    "amount": "4"
                }
            ]
        },
        {
            "gender": [
                {
                    "title": "Male",
                    "link": "#male",
                    "amount": "67"
                },
                {
                    "title": "Female",
                    "link": "#female",
                    "amount": "3"
                }
            ]
        }
    ]
}]
}];

alert(JSON.stringify(searchresults))
于 2013-09-04T16:56:35.093 回答
0

,如果对象中的键/值对后面有另一个,则只有逗号。(同样适用于数组)

例如:

var a = {
   key  : 'value',
   keyB : 'value'   // <-- there is no trailing comma before an object ends
};
于 2013-09-04T16:45:06.310 回答
0

你知道http://jsonlint.com/吗?

您必须意识到,javascript 中的对象与关联数组几乎相同。

我认为您应该阅读更多关于 Javascript 中的对象和数组的内容。

尝试这个:

var searchresults = {
        "providerlisting": [
            {
                "nametitle": "Cory M Spears, MD, FACP",
                "caretype": "Internaenter code herel Medicine",
                "preferredProvider": true,
                "address1": "289 N. Highland Ave.",
                "address2": "",
                "cityStateZip": "Atlanta, GA 30306",
                "coverage": "/images/example.png",
                "status": "Out of Network",
                "psn": "",
                "dcontact": "urlhere",
                "save": "urlhere",
                "rating": "urlhere"
            },
            {
                "nametitle": "Jimmy Dean, MD, FACP",
                "caretype": "External Medicine",
                "preferredProvider": false,
                "address1": "3 Piedmont Rd.",
                "address2": "",
                "cityStateZip": "Atlanta, GA 30706",
                "coverage": "/images/example2.png",
                "status": "In Network",
                "psn": "urlhere",
                "dcontact": "urlhere",
                "save": "urlhere",
                "rating": "urlhere"
            },
            {
                "nametitle": "John Doe, DD, PM",
                "caretype": "Internal Medicine",
                "preferredProvider": true,
                "address1": "500 Ponce De Leon Ave",
                "address2": "Suite 5",
                "cityStateZip": "Atlanta, GA 30706",
                "coverage": "/images/example2.png",
                "status": "Out of Network",
                "psn": "urlhere",
                "dcontact": "urlhere",
                "save": "urlhere",
                "rating": "urlhere"
            }
        ],
        "categories": {
            "categoryMenu": {
                "providertype": [
                    {
                        "title": "Doctor",
                        "link": "#doctor",
                        "amount": "400"
                    },
                    {
                        "title": "Hospital",
                        "link": "#hospital",
                        "amount": "40"
                    },
                    {
                        "title": "Urgent Care",
                        "link": "#urgentCare",
                        "amount": "37"
                    }
                ],
                "specialty": [
                    {
                        "title": "Allergy and Immunology",
                        "link": "#allergyAndImmunology",
                        "amount": "2"
                    },
                    {
                        "title": "Audiology",
                        "link": "#audiology",
                        "amount": "3"
                    },
                    {
                        "title": "Allergy and Immunology",
                        "link": "#allergyAndImmunology",
                        "amount": "6"
                    },
                    {
                        "title": "Ambulatory Surgical Center",
                        "link": "#ambulatorySurgicalCenter",
                        "amount": "4"
                    }
                ],
                "gender": [
                    {
                        "title": "Male",
                        "link": "#male",
                        "amount": "67"
                    },
                    {
                        "title": "Female",
                        "link": "#female",
                        "amount": "3"
                    }
                ]
            }
        }
    }
于 2013-09-04T16:54:56.137 回答