Javascript&;嵌套JSON问题
因此,我试图组合一些JSON并将其解析为jquery,但我的JSON语法出了问题。我试着通过验证器运行它,但它并没有真正告诉我我做错了什么。有人能指出我的错误吗Javascript&;嵌套JSON问题,javascript,jquery,json,Javascript,Jquery,Json,因此,我试图组合一些JSON并将其解析为jquery,但我的JSON语法出了问题。我试着通过验证器运行它,但它并没有真正告诉我我做错了什么。有人能指出我的错误吗 var searchresults = [ { "providerlisting": [ { "nametitle": "Cory M Spears, MD, FACP", "caretype": "Internal Medicine", "preferredProvide
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"
}
]
}
}]
}];
卸下每一页末尾的
,
"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"
}]
}]
}]
}];
卸下每一页末尾的
,
"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"
}]
}]
}]
}];
如果在对象中的键/值对后面有另一个,则该键/值对后面只有
,
逗号。(阵列也是如此)
例如:
var a = {
key : 'value',
keyB : 'value' // <-- there is no trailing comma before an object ends
};
var a={
键:“值”,
keyB:'value'/如果在对象中有另一个键/值对,则在该键/值对之后只有,
逗号。(数组也是如此)
例如:
var a = {
key : 'value',
keyB : 'value' // <-- there is no trailing comma before an object ends
};
var a={
键:“值”,
你知道吗
您必须意识到,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"
}
]
}
}
}
你知道吗
您必须意识到,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"
}
]
}
}
}
显然在第16行报告了一个错误。有一个错误的逗号。这是真实JSON中的一个错误,但这不是您发布的;您发布了一个JavaScript语句,在JavaScript中也不会是错误(旧的IE版本除外)。您当前拥有的是一个脚本,它将一个巨大的对象文本分配给一个变量。如果您愿意(验证器验证的内容),您只需要获取文本,而不需要其周围环境。显然在第16行报告了一个错误。有一个错误的逗号。这是真实JSON中的一个错误,但不是您发布的;您发布了一个JavaScript语句,在JavaScript中不会是错误(旧IE版本除外)。您当前拥有的是一个脚本,该脚本将一个巨大的对象文本分配给一个变量。如果需要(验证程序验证的内容),您只需要获取文本,而不需要它的周围环境。当我将其放入Notepad++并用JSMin格式化时,它看起来还缺少一个右方括号]
end@valverij是的,确实如此,添加了完整的工作副本,因为很难指出哪一行,etcThanks,它仍然没有通过jso运行尽管如此。我猜它不喜欢javascript。我应该在哪里复制并结束复制才能让它通过验证器正确运行?@Chad它传递给JSONLint,这是一个json对象验证器,而不是javascript验证器。要在那里测试它,您需要删除变量声明/赋值和;
最后以{“providerlisting”开始:[{…?当我把它放到记事本++中并用JSMin格式化时,它看起来也缺少了一个结束方括号]
在end@valverij是的,确实如此,添加了完整的工作副本,因为很难指出哪一行,etcThanks,它仍然没有通过jsonlint.com运行。我猜它不喜欢javascript。我应该在哪里复制并结束复制,以便让它通过验证程序正确运行?@Chad it传递给jsonlint,that是一个json对象验证器,而不是javascript验证器。要在那里测试它,您需要删除变量声明/赋值和结尾处的;
,所以从{“ProviderList”开始:[{?