【问题标题】:What is the wrong with my JSON code? [closed]我的 JSON 代码有什么问题? [关闭]
【发布时间】:2023-04-01 12:52:01
【问题描述】:

谁能告诉我为什么我的 JSON 文件在解析时会抛出错误?我正在尝试使用 kartograph 制作地图?我使用 JSLINT 得到这些错误(如下所示)

{
  "proj": { "id": "sinusoidal", 
   "lon0": 134.25},
  "layers": [
    {
      "background": {"special": "sea"},
      "styles": {"fill": "lightblue"}
    },
    {
      "graticule": {"special": "graticule",
      "latitudes": 1,
      "longitudes": 1}
    },
     { "id": "Aus"
       "src": "myfile"
       "simplify": false
       }, 
    { "id": "trees",
      "src": "myfile",
      "simplify": true },
   {'id': 'crops'
      "src": "myfile",
      "simplify": true
   },
     { "id": "depth"
       "src": "myfile",
       "simplify": true
   },
   { "id": "states",
      "src": "myfile"}
  ],

  "export": {
    "width": "auto",
    "height": "auto"
  },
  "bounds": {
    "padding": 0.02,
    "mode": "bbox",
    "data": [92, -44, 181, -2],
    "crop": [112, -44, 154, -9]

  }
}

我使用 JSLINT 遇到的错误是

Line 14, column 8: Expected '}' to match '{' from line 13 and instead saw 'src'.
           "src": "myfile"

Line 14, column 13: Expected ']' to match '[' from line 3 and instead saw ':'.
           "src": "myfile"

Line 14, column 15: Expected '}' to match '{' from line 1 and instead saw 'D:/karto/Aus/Ausfull/Ausfull.shp'.
           "src": "myfile"

Line 15, column 8: Expected '(end)' and instead saw 'simplify'.
           "simplify": false

* 不明白如何解决这些错误??

【问题讨论】:

  • 你少了很多逗号。
  • 您在该区域缺少,
  • {"id": "Aus" "src": "myfile" "simplify": false} 缺少一些 ,s。
  • 不要混用 '"。使用"id" 而不是'id'
  • 如果您使用标准缩进,您可以更轻松地发现这些错误。我非常喜欢将大括号放在自己的线上,这样很容易看到。像 sublime 这样的工具使这变得简单:您可以突出显示多行区域并使用制表符来缩进所有行。

标签: javascript json jslint


【解决方案1】:

字符串必须带有双引号,并且您错过了一些逗号

  {
        "proj": {
            "id": "sinusoidal",
                "lon0": 134.25
        },
            "layers": [{
            "background": {
                "special": "sea"
            },
                "styles": {
                "fill": "lightblue"
            }
        }, {
            "graticule": {
                "special": "graticule",
                    "latitudes": 1,
                    "longitudes": 1
            }
        }, {
            "id": "Aus",
                "src": "myfile",
                "simplify": false
        }, {
            "id": "trees",
                "src": "myfile",
                "simplify": true
        }, {
            "id": "crops",
                "src": "myfile",
                "simplify": true
        }, {
            "id": "depth",
                "src": "myfile",
                "simplify": true
        }, {
            "id": "states",
                "src": "myfile"
        }],

            "export": {
            "width": "auto",
                "height": "auto"
        },
            "bounds": {
            "padding": 0.02,
                "mode": "bbox",
                "data": [92, -44, 181, -2],
                "crop": [112, -44, 154, -9]

        }
    }

【讨论】:

  • 谢谢问题解决了:)
猜你喜欢
  • 2013-02-11
  • 1970-01-01
  • 2014-12-07
  • 1970-01-01
  • 2014-04-02
  • 1970-01-01
  • 2022-09-22
  • 2016-02-27
  • 2022-06-10
相关资源
最近更新 更多