我试图遍历GeoJSON文件(如下),并最终在“属性”中填充带有一些属性的数组。我会通过找到的各种示例来说明问题。我是否需要嵌入另一个$ .each()才能进入属性。如果不是很明显,我是陌生的,我已经碰壁了。
到目前为止,我有:
$(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');
});
});
而我的json如下:
{
"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
]
}
}
]
}