javascript - JS 脚本语法错误

标签 javascript json qgis

我有以下 .js 文件,Dreamweaver 在第 2 行报告语法错误。

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": 0,
      "properties": {
        "Id": 0,
        "Title": "River & Trail HQ",
        "Other": null,
        "Parking": "Yes"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -8649997.6690437607,
          4769179.73322534
        ]
      }
    }
  ]
}

好像有问题

"type": "FeatureCollection",

线。

最佳答案

如果这是整个 JavaScript 文件,那么它会给您一个错误,因为它被解释为 block 而不是对象文字。要解决此问题,您可以将其分配给某些内容,例如

var someObj = {
    "type": "FeatureCollection",
    ...
}

您可能还会考虑 JSON 文件(可能就是这种情况,因为自由 float 的对象文字无论如何也不会给您带来多大好处)。 JSON 和 JavaScript 不一样。如果您确实需要 JSON 文件,请将其保存为这样的文件 (.json)。

关于javascript - JS 脚本语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506204/

相关文章:

javascript - 当前 HTML 页面在新标签打开时滚动(网络中没有 JS),如何避免滚动?

javascript - 火狐附加 SDK : Run content script in new tab only once

javascript - 清除间隔未捕获

wcf - 将 JSON 发送到 WCF Rest 服务 - 对象始终为 null

json - 从 AWS Lambda 函数解析 JSON 答案

python - 将 QGIS 模块导入 Python (Anaconda)

python - 使用networkx.algorithms.approximation.steinertree.steiner_tree提取斯坦纳树时出错

javascript - 以 Angular 方式将事件传递给triggerHandler

json - 谷歌电子表格检索 JSON 提要

python - 从 Python 运行 QGIS 时没有名为 sip 的模块