我希望能够创建一个JSON对象,以便我可以像这样访问它。
education.schools.UNCC.graduation
目前,我的JSON是这样的:
var education = {
"schools": [
"UNCC": {
"graduation": 2015,
"city": "Charlotte, NC",
"major": ["CS", "Spanish"]
},
"UNC-CH": {
"graduation": 2012,
"city": "Chapel Hill, NC"
"major": ["Sociology", "Film"]
}
],
"online": {
"website": "Udacity",
"courses": ["python", "java", "data science"]
}
};
当我转到Lint my JSON时,我收到一条错误消息。 我知道我可以重新格式化我的对象来访问它(如下所示),但我不想这样做。我希望能够拨打学校名称,而不是使用索引号。
education.schools[1].graduation
答案 0 :(得分:0)
对象具有命名键。数组是成员列表。
用对象替换"schools"
的值。将[]
更改为{}
。
答案 1 :(得分:-1)
这是你的JSON更正。 您的JSON无效。
{
"schools": [
{
"UNCC": {
"graduation": "2015",
"city": [
"CS",
"Spanish"
],
"major": [
"CS",
"Spanish"
]
}
},
{
"UNC-CH": {
"graduation": "2012",
"city": [
"Chapel Hill",
"NC"
],
"major": [
"Sociology",
"Film"
]
}
}
],
"online": {
"website": "Udacity",
"courses": [
"python",
"java",
"data science"
]
}
}
<强>解释强>:
http://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html