php - 我有这个外部 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; ?>
解决方案
所有必需的属性都在属性键下。更改您的代码以阅读下面的内容。
echo $obj->properties->NAME ;
echo $obj->properties->Northing;
echo $obj->properties->Eastinglink;
推荐阅读
- angular - 错误 _co.routeToBrainstoming 不是 Angular 2 中的函数
- ios - 在展开可选值时意外发现 nil:UITableView.delegate = self
- node.js - Sendgrid V3 NodeJS 到单独的fundtion文件
- java - Spring MVC - 访问web下res文件夹中的文件
- python - 通过带有条件的生成器表达式分配两个变量?
- slack - Slack user_id 和 username 是否有已发布的格式?
- tensorflow - flatten layer的影响及其正确使用方法
- html - 导航栏未正确缩放
- c++ - 头文件中 .h 扩展名的意义是什么?
- mongodb - MongoDB 2.4 - 按日期聚合组,间隔 120 天