我有这个外部 geojson 文件。我想循环并回显属性对象(例如 "Name" "Easting" "Northing")。我没有弄错

I have this external geojson file. i would like to loop and echo the properties object (e.g "Name" "Easting" "Northing"). i dont were am getting wrong

{ "type": "FeatureCollection", "name": "Trial",

"features": [ { "type": "Feature", "properties": { "NAME": "Muwaya Pri. Sch", "Easting": 686607.293, "Northing": 8561595.506 }, "geometry": { "type": "Point", "coordinates": [ 686607.293, 8561595.50599999912 ] } },

{ "type": "Feature", "properties": { "NAME": "Munkulungwe Pri. Sch", "Easting": 690206.558, "Northing" : 8550186.399 }, "geometry": { "type": "Point", "coordinates": [ 690206.558, 8550186.399 ] } },

{ "type": "Feature", "properties": { "NAME": "Fiwale Pri.Sch", "Easting": 685977.67, "Northing" : 8539029.88 }, "geometry": { "type": "Point", "coordinates": [ 685977.67, 8539029.88 ] } },

{ "type": "Feature", "properties": { "NAME": "Mwatishi School", "Easting": 702707.723, "Northing" : 8554903.974 }, "geometry": { "type": "Point", "coordinates": [ 702707.723, 8554903.97399999946 ] } } ] }

代码

              <?php$getfile = file_get_contents('test.Geojson');  ?>
              <?php$jsonfile = json_decode($getfile);  ?>

           <?php foreach ($jsonfile->features as $index => $obj): ?>
            <?php echo $obj->Name; ?>
            <?php echo $obj->Northing; ?>
           <?php echo $obj->Eastinglink; ?>

所有必需的属性都在属性键下。更改您的代码以阅读下文。

echo $obj->properties->NAME ;
echo $obj->properties->Northing; 
echo $obj->properties->Eastinglink;