Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将GeoJSON加载到OpenLayers 3 VectorLayer时出错:JSON.parse预期的属性名称_Javascript_Json_Openlayers 3_Geojson - Fatal编程技术网

Javascript 将GeoJSON加载到OpenLayers 3 VectorLayer时出错:JSON.parse预期的属性名称

Javascript 将GeoJSON加载到OpenLayers 3 VectorLayer时出错:JSON.parse预期的属性名称,javascript,json,openlayers-3,geojson,Javascript,Json,Openlayers 3,Geojson,我试图将GeoJSON字符串加载到矢量层,但在JSON数据的第1行第2列遇到了一个JSON.parse:expected property name或'}'问题 已经读过关于like的som文本,但无法解决我的问题 这是我的JSON。在进行测试 我的OpenLayers资料(featuresText是上面的GeoJSON): 错误位于ol debug.js:45632。JSON字符串似乎还可以。我不明白 我也读过这篇文章。查看您的geojson和错误消息,我将尝试回答。第1行第2列是一个单引号。

我试图将GeoJSON字符串加载到矢量层,但在JSON数据的第1行第2列遇到了一个
JSON.parse:expected property name或'}'问题

已经读过关于like的som文本,但无法解决我的问题

这是我的JSON。在进行测试

我的OpenLayers资料(
featuresText
是上面的GeoJSON):

错误位于
ol debug.js:45632
。JSON字符串似乎还可以。我不明白


我也读过这篇文章。

查看您的geojson和错误消息,我将尝试回答。第1行第2列是一个单引号。JSON需要双引号来保存字符串

此外,从:

要素对象必须具有名为“属性”的成员。properties成员的值是一个对象(任何JSON对象或JSON空值)

您的功能没有属性

有了这两个变化:

{"type": "FeatureCollection", "crs": {"type": "name","properties": {"name": "EPSG:4326"}},"features": [{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1996056,-22.9109588],[-43.1993777,-22.9115575],[-43.1993539,-22.9116778],[-43.1993568,-22.9118156],[-43.199378,-22.9123812]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199378,-22.9123812],[-43.1994332,-22.9131767]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1994332,-22.9131767],[-43.1994563,-22.9141351],[-43.1994364,-22.9142456],[-43.199379,-22.9143303]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199379,-22.9143303],[-43.1985846,-22.9144791]]]}}]}

我在

上成功显示了您的geojson。查看您的geojson和错误消息,我将尝试回答。第1行第2列是一个单引号。JSON需要双引号来保存字符串

此外,从:

要素对象必须具有名为“属性”的成员。properties成员的值是一个对象(任何JSON对象或JSON空值)

您的功能没有属性

有了这两个变化:

{"type": "FeatureCollection", "crs": {"type": "name","properties": {"name": "EPSG:4326"}},"features": [{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1996056,-22.9109588],[-43.1993777,-22.9115575],[-43.1993539,-22.9116778],[-43.1993568,-22.9118156],[-43.199378,-22.9123812]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199378,-22.9123812],[-43.1994332,-22.9131767]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1994332,-22.9131767],[-43.1994563,-22.9141351],[-43.1994364,-22.9142456],[-43.199379,-22.9143303]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199379,-22.9143303],[-43.1985846,-22.9144791]]]}}]}

我在

上成功地显示了您的geojson,为什么在这里而不是在GIS中?我认为这是一个JSON格式的问题。为什么在这里而不是在GIS中?我认为这是一个JSON格式的问题。太好了。我发现有人说的恰恰相反。JSON必须是单引号。我认为问题可能只是
properties
成员。我现在就试试并公布结果。你是对的。现在一切都很好(嗯,我在样式方面遇到了一些问题,但这对GIS S.E.来说是个问题)。谢谢顺便说一句,geojson.io为+1。@MagnoC在字符串上引用“字符串是由零个或多个Unicode字符组成的序列,用双引号括起来,[…]“。太好了。我发现有人的说法正好相反。JSON必须是单引号。我想问题可能只是
属性
成员。现在就试试并发布结果。你说得对。现在一切都很好(嗯,我在样式方面遇到了一些问题,但这对GIS S.E.来说是个问题。).Thank.BTW,+1表示geojson.io。@MagnoC引用字符串上的“字符串是零个或多个Unicode字符的序列,用双引号括起来,[…]”。
{"type": "FeatureCollection", "crs": {"type": "name","properties": {"name": "EPSG:4326"}},"features": [{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1996056,-22.9109588],[-43.1993777,-22.9115575],[-43.1993539,-22.9116778],[-43.1993568,-22.9118156],[-43.199378,-22.9123812]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199378,-22.9123812],[-43.1994332,-22.9131767]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.1994332,-22.9131767],[-43.1994563,-22.9141351],[-43.1994364,-22.9142456],[-43.199379,-22.9143303]]]}},{"type": "Feature","properties": {}, "geometry":{"type":"MultiLineString","coordinates":[[[-43.199379,-22.9143303],[-43.1985846,-22.9144791]]]}}]}