首页 > 解决方案 > 我有这个外部 geojson 文件。我想循环和回显属性对象(例如“名称”“东”“北”)。我没有弄错

问题描述

{“类型”:“FeatureCollection”,“名称”:“试用”,

“特征”:[{“类型”:“特征”,“属性”:{“名称”:“Muwaya Pri. Sch”,“东向”:686607.293,“北向”:8561595.506},“几何”:{“类型": "点", "坐标": [ 686607.293, 8561595.50599999912 ] } },

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

{“类型”:“特征”,“属性”:{“名称”:“Fiwale Pri.Sch”,“东”:685977.67,“北”:8539029.88},“几何”:{“类型”:“点” , "坐标": [ 685977.67, 8539029.88 ] } },

{ "type": "Feature", "properties": { "NAME": "Mwatishi School", "Easting": 702707.723, "Northing": 8554903.974 }, "geometry": { "type": "Point", "坐标”:[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; ?>

标签: phphtmljsonperformancegeojson

解决方案


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

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

推荐阅读