代码不会验证

时间:2016-05-18 03:12:57

标签: javascript json lint

Json lint不会验证我的代码。你知道为什么吗?

这是更新后的代码。这是一个包括学校和在线教育的对象。

var education ={
    "schools": [
      {
        "name": "University of Hertfordshire",
        "location": "Hertfordshir e, UK",
        "degree": "Masters",
        "Major": ["Computer Science"],
        "graduation": "2017 (expected)"
      },
       {
        "name": "University of Applied Sciences",
        "location": "Jena, German",
        "degree": "Diplom",
        "Major": ["Business Administration and Information Systems"],
        "graduation": "2010"
    }
  ]
} ,

    "onlineCourses": [
    {
        "title": "Javascript Syntax",
        "school": "Udacity",
        "dates": "May 2016"
    }]
}

2 个答案:

答案 0 :(得分:1)

{
    "schools": [{
        "name": "University of Hertfordshire",
        .....
    }, {
        "name": "University of Applied Sciences",
        .....
    }]
}, {
    "onlinecourse": [{
        "title": "Javascript Syntax",
        ....
    }]
}

你有两个悬挂在这里的物品,需要在[]里面像

 [
  {
        "schools": [{
            "name": "University of Hertfordshire"
             .....
        }, {
            "name": "University of Applied Sciences"
             ....
        }]
    }, {
        "onlinecourse": [{
            "title": "Javascript Syntax"
          .....
        }]
    }
]

修改

在您更新的代码中

{
    "schools": [
      {
        "name": "University of Hertfordshire"
        .....
      },
       {
        "name": "University of Applied Sciences"   
         .....   
    } ]
} ,

    "onlineCourses": [
    {
        "title": "Javascript Syntax"
         ......
    }]
}

注意}数组作为对象标记结束后的schools{之前没有onlinecourse向解析器建议{{1} }是另一个对象的一部分和所有混乱的bcoz,解析器认为你有多个根元素。这是解决方案:

onlinecourse

ofcourse在验证时从json中取出注释,因为它们在json中是不允许的。

答案 1 :(得分:0)

在关闭学校阵列的 ArrayAdapter arrayAdapter = new ArrayAdapter(YourClassName.this,android.R.layout.simple_list_item_1,friends); listView.setAdapter(arrayAdapter); 之后看起来你有一个迷路}

]

STRAY ==> }

{
    "schools": [
    ....  
  ]

如上所述,请务必检查错误