【问题标题】:what Error in this json file? [closed]这个 json 文件中有什么错误? [关闭]
【发布时间】:2014-06-04 13:12:22
【问题描述】:

当我在浏览器上运行这个 json 文件时,我发现了错误,我不知道为什么?

这是我的完整代码:

 [
 {
     name: "Samsung Tab 3",
     price: 500,
     description:
                    "Samsung Tab 3 is very well "
                 + "Samsung Tab 3 is very well ",
     images: [
          "images/tablet1.png",
          "images/tablet1-thumb.png"
     ],
     reviews: [
     {
         stars: 5,
         body: "I Love this Tab",
         author: "Michael.Gamel@hotmail.com"
     },
     {
         stars: 1,
         body: "this tab sucks",
         author: "samir@hotmail.com"
     }
     ],
     processor: " Core™2 Duo",
     ram: "1 GB",
     colors: ["White","Red","Blue"],
     canPurchase: true,
     soldOut: false
 }
 ,
 {
     name: "Apple iPad 4",
     price: 500.50,
     description:
                    "Apple iPad 4 is very well "
                 + "Apple iPad 4 is very well ",
     images: [
          "images/tablet2.png",
          "images/tablet2-thumb.png"
     ],
     reviews: [
     {
         stars: 3,
         body: "I Love this Tab",
         author: "Michael.Gamel@hotmail.com"
     },
     {
         stars: 4,
         body: "this tab sucks",
         author: "samir@hotmail.com"
     }
     ],
     processor: "core i3",
     ram: "2 GB",
     colors: ["Black", "Yellow", "Brown"],
     canPurchase: true,
     soldOut: false
 }
    ]

我发现名称错误,我的浏览器告诉我:

错误:第 2 行的解析错误: [ { 名称:“三星标签 3 -----------------^ 期待“STRING”、“}”

这是什么意思??!!

【问题讨论】:

  • 这是你可以自己调试的东西:jsonlint.com
  • 这个问题似乎跑题了,因为 SO 不是调试服务。

标签: javascript asp.net json json.net getjson


【解决方案1】:

您需要引用属性名称才能使其成为有效的 json:http://json.org/example

【讨论】:

    【解决方案2】:

    您在 key 名称周围缺少引号...

    "name": "Samsung Tab 3",
    

    这里的主要问题是描述中的格式。您会遇到以下语法问题:

    "Samsung Tab 3 is very well "
                     + "Samsung Tab 3 is very well ",
    

    也请查看JSONLint,这将有助于验证您的 JSON。

    【讨论】:

      【解决方案3】:

      这是因为 JavaScript 字符串连接 像这样:

      description : "Samsung Tab 3 is very well " 
      + "Samsung Tab 3 is very well "
      

      试试这个:

      [{
          name : "Samsung Tab 3",
          price : 500,
          description : "Samsung Tab 3 is very well " + "Samsung Tab 3 is very well ",
          images : [
              "images/tablet1.png",
              "images/tablet1-thumb.png"
          ],
          reviews : [{
                  stars : 5,
                  body : "I Love this Tab",
                  author : "Michael.Gamel@hotmail.com"
              }, {
                  stars : 1,
                  body : "this tab sucks",
                  author : "samir@hotmail.com"
              }
          ],
          processor : " Core™2 Duo",
          ram : "1 GB",
          colors : ["White", "Red", "Blue"],
          canPurchase : true,
          soldOut : false
      }, {
          name : "Apple iPad 4",
          price : 500.50,
          description : "Apple iPad 4 is very well " + "Apple iPad 4 is very well ",
          images : [
              "images/tablet2.png",
              "images/tablet2-thumb.png"
          ],
          reviews : [{
                  stars : 3,
                  body : "I Love this Tab",
                  author : "Michael.Gamel@hotmail.com"
              }, {
                  stars : 4,
                  body : "this tab sucks",
                  author : "samir@hotmail.com"
              }
          ],
          processor : "core i3",
          ram : "2 GB",
          colors : ["Black", "Yellow", "Brown"],
          canPurchase : true,
          soldOut : false
      }]
      

      这里是Demo

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多