Converting GeoJSON object to Javascript Array - Stack Overflow

I need to convert a GeoJSON output from a server to a Javascript array; I have done some searches and t

I need to convert a GeoJSON output from a server to a Javascript array; I have done some searches and they were for the 'regular' JSON outputs and not the GeoJSON. Here is the output from the Server:

{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

And here is what I need (note, no quotation on the 'features' variable needed):

features = [{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

I think I need to find the 'features' property and then loop through its objects? Thanks!

I need to convert a GeoJSON output from a server to a Javascript array; I have done some searches and they were for the 'regular' JSON outputs and not the GeoJSON. Here is the output from the Server:

{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

And here is what I need (note, no quotation on the 'features' variable needed):

features = [{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

I think I need to find the 'features' property and then loop through its objects? Thanks!

Share Improve this question asked Sep 30, 2014 at 19:07 IrfanClemsonIrfanClemson 1,7796 gold badges35 silver badges56 bronze badges 4
  • So you have a valid JSON string, and you want to convert it to something that is not valid ? – adeneo Commented Sep 30, 2014 at 19:10
  • features = JSON.parse('{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}').features – Malk Commented Sep 30, 2014 at 19:11
  • I need to convert to a standard Javascript array for something in my javascript code; the regular (valid) GeoJSON is being used fine in some other part of the code. Thanks. – IrfanClemson Commented Sep 30, 2014 at 19:15
  • @Malk: I need to do in a loop--can't hard code the values. Thanks. – IrfanClemson Commented Sep 30, 2014 at 19:16
Add a ment  | 

1 Answer 1

Reset to default 8

A GeoJSON object is still a JSON object (it's the first thing their documentation says).

http://geojson/geojson-spec.html

If you want to store the features PROPERTY of a GeoJSON object, access the property value as you would normally after conversion to a javascript object and push that property into a new variable, or use as is.

var geoObject = JSON.parse(geoJSONObject);
var features = [];

features = geoObject.features;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743757006a4501938.html

相关推荐

  • Converting GeoJSON object to Javascript Array - Stack Overflow

    I need to convert a GeoJSON output from a server to a Javascript array; I have done some searches and t

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信