Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to iterate through a GeoJSON file (below) and eventually populate an array with a few attributes within "properties". I keep coming up short working through various examples I can find. Do I need to embed another $.each() to get to properties. If it isn't obvious I'm new to this and I've hit the wall.

What I have so far:

$(document).ready(function () {    
            $.getJSON('testpoint.geojson', function (data) {
                var items = [];
                $.each(data.features, function (key, val) {
                    items.push('<li id="' + key + '">' + val + '</li>');
                });
                $('<ul/>', {
                    'class':'my-new-list',
                    html:items.join('')
                }).appendTo('body');
            });
        });

And my json is as follows:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "gid": 1,
                "PID": "9-18-3",
                "BCT": "BCT126",
                "OWNER_TYPE": "A",
                "LOCNO": 0,
                "LOCEXT": "",
                "STREET": "CROSBY LANE",
                "ACQUIRED": "5/7/2010",
                "GRANTOR": "John A. SPARGO",
                "UPLAND": 0,
                "WETLAND": 3.96,
                "TOTAL": 3.96,
                "HABITAT": "salt marsh"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -70.03209,
                    41.78278
                ]
            }
        }
    ]
}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You are almost there. Another .each for val.properties should work:

$.each(data.features, function (key, val) {
    $.each(val.properties, function(i,j){
        items.push('<li id="' + i + '">' + j + '</li>');
    })              
});
share|improve this answer
1  
Thanks Cyrus, that did the trick. I tried every combo but that. I'm a beginner and iterations can become overwhelming quickly –  geomajor56 Jul 19 '12 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.