【发布时间】:2014-11-25 12:30:05
【问题描述】:
我需要将来自服务器的 GeoJSON 输出转换为 Javascript 数组;我已经进行了一些搜索,它们是针对“常规”JSON 输出而不是 GeoJSON。这是服务器的输出:
{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}
这就是我需要的(注意,不需要对“特征”变量进行引用):
features = [{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}
我想我需要找到 'features' 属性,然后遍历它的对象?谢谢!
【问题讨论】:
-
所以你有一个有效的 JSON 字符串,你想把它转换成无效的东西?
-
features = JSON.parse('{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}').features -
我需要将我的 javascript 代码中的某些内容转换为标准的 Javascript 数组;常规(有效)GeoJSON 在代码的其他部分中使用得很好。谢谢。
-
@Malk:我需要循环执行——不能对值进行硬编码。谢谢。
标签: javascript arrays geojson