我该如何修复这个JSON文件?

时间:2017-02-02 07:57:24

标签: angularjs json

我想创建一个包含以下格式的JSON文件:对于每个课程名称,有一些类别,并且对于每个类别,还有一些其他详细信息即可。我的JSON文件如下:

[
   {
      "$id":"1",
      "name":"Business"{
      "cat":"CuberSecurity"{
         "img":"img3_1.jpg",
      "cat_kurs":"7-course specialization",
      "txt":"Rice University"
      },
    "cat":"Google Cloud Platform for Systems Operations"{
       "img":"img3_2.jpg",
      "cat_kurs":"6-course specialization",
      "txt":"University of California"
    }
      }
   },
   {
      "$id":"2",
      "name":"Computer Science"{

      "cat":"Fundamentals of Computing"{
      "img":"img3_1.jpg",
      "cat_kurs":"7-course specialization",
      "txt":"Rice University"
      },
      "cat":"Data Structures and algorithms"{
      "img":"img3_2.jpg",
      "cat_kurs":"6-course specialization",
      "txt":"University of California"
      },
      "cat":"Probabilistic Graphical Models"{
       "img":"img3_3.jpg",
      "cat_kurs":"3-course specialization",
      "txt":"Stanford University"
      },
      "cat":"Bioinformatics"{
      "img":"img3_4.jpg",
      "cat_kurs":"7-course specialization",
      "txt":"University of California"
      },
      "cat":"Algorithms"{
      "img":"img3_5.jpg",
      "cat_kurs":"4-course specialization",
      "txt":"Stanford University"
      }
    }
  }
]

我在编辑器中看过它,我知道它充满了错误。请告诉我如何纠正它。

3 个答案:

答案 0 :(得分:1)

如果synxtax正确的话,我建议只用几行开始扩展它,有很多网站可以帮助你解决这个问题。只是google json在线验证器。

编辑:小例子:

[{
    "$id": "1",
    "name": "Business",
    "cat": 
    [{
        "cname": "CyberSecurity",
        "img": "img3_1.jpg",
        "cat_kurs": "7-course specialization",
        "txt": "Rice University"
    }, {
        "cname": "Google Cloud Platform for Systems Operations",
        "img": "img3_2.jpg",
        "cat_kurs": "6-course specialization",
        "txt": "University of California"
    }]
}]

答案 1 :(得分:0)

我认为在尝试创建JSON结构时应该使用JSON validator,这是非常有用的。

我在这里修改了你的JSON:

[
   {
      "$id":"1",
      "name":"Business",
      "cat":[
         {
            "name":"CuberSecurity",
            "img":"img3_1.jpg",
            "cat_kurs":"7-course specialization",
            "txt":"Rice University"
         },
         {
            "name":"Google Cloud Platform for Systems Operations",
            "img":"img3_2.jpg",
            "cat_kurs":"6-course specialization",
            "txt":"University of California"
         }
      ]
   },
   {
      "$id":"2",
      "name":"Computer Science",
      "cat":[
         {
            "name":"Fundamentals of Computing",
            "img":"img3_1.jpg",
            "cat_kurs":"7-course specialization",
            "txt":"Rice University"
         },
         {
            "name":"Data Structures and algorithms",
            "img":"img3_2.jpg",
            "cat_kurs":"6-course specialization",
            "txt":"University of California"
         },
         {
            "name":"Probabilistic Graphical Models",
            "img":"img3_3.jpg",
            "cat_kurs":"3-course specialization",
            "txt":"Stanford University"
         },
         {
            "name":"Bioinformatics",
            "img":"img3_4.jpg",
            "cat_kurs":"7-course specialization",
            "txt":"University of California"
         },
         {
            "name":"Algorithms",
            "img":"img3_5.jpg",
            "cat_kurs":"4-course specialization",
            "txt":"Stanford University"
         }
      ]
   }
]

答案 2 :(得分:-1)

我有另一个小例子,有点不同。

{
  "courses": [
    {
      "id": "1",
      "categories": [
        {
          "cat_id": "1",
          "name": "Advanced Science",
          "date": "1234"
        },
        {
          "cat_id": "2",
          "name": "Advanced Math",
          "date": "1234"
        },
        {
          "cat_id": "3",
          "name": "Advanced History",
          "date": "1234"
        }
      ]
    },
    {
      "id": "2",
      "categories": [
        {
          "cat_id": "1",
          "name": "Advanced Science",
          "date": "1234"
        },
        {
          "cat_id": "2",
          "name": "Advanced Math",
          "date": "1234"
        },
        {
          "cat_id": "3",
          "name": "Advanced History",
          "date": "1234"
        }
      ]
    }
  ]
}