我需要帮助来从格式化后的文件中获取数据,而不是习惯于从中获取数据。我提供了数据外观的屏幕截图。我需要获取坐标数组,但是每次调用新的for循环时,它都会进入属性数组。
我已附加我的代码,因此您可以看到我的位置。我必须靠近,因为我在数组中获取数组,但无法弄清楚如何访问该数组的数据。
$json_data = file_get_contents('rebar.txt');
$json = json_decode($json_data, true);
foreach($json as $key => $value)
{
echo $key;
//var_dump($value);
//echo "<br>";
foreach ($value as $key1 => $value1)
{
echo "<pre>";
print_r($value1);
echo "</pre>";
}
}
编辑-包含一些非格式的JSON
{"type":"FeatureCollection","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}},"features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.345588,15.575967]},"properties":{"id":"219089-27","tag_id":27,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"0.922085","agreement":10,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/f3f7fc0f7e68d702803e170bd77da45d.jpg","timestamp":"2017-10-11T13:01:46.493Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":6360}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.348517,15.590673]},"properties":{"id":"219089-62","tag_id":62,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"1.000000","agreement":31,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/b4b26d171c1767d244a1be66b0fe3663.jpg","timestamp":"2017-10-11T13:01:39.090Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":1780}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.342107,15.592311]},"properties":{"id":"219089-164","tag_id":164,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"1.000000","agreement":19,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/0451894861f5da83539ce5baa3b61193.jpg","timestamp":"2017-10-11T13:01:38.683Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":4801}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.341098,15.591505]},"properties":{"id":"219089-175","tag_id":175,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"1.000000","agreement":37,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/03eaeb046b60e6ad307f23112f8e28e9.jpg","timestamp":"2017-10-11T13:01:46.131Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":4801}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.342911,15.586736]},"properties":{"id":"219089-220","tag_id":220,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"1.000000","agreement":25,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/c544b3bda7730c941472bdabc7157629.jpg","timestamp":"2017-10-11T13:01:39.090Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":329}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.422756,15.456392]},"properties":{"id":"219089-265","tag_id":265,"label":"Flooded / Damaged Building","tagger_id":2349740,"type_id":1955,"score":"1.000000","agreement":18,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/712d3036d5f5ee905f113628dbf9041c.jpg","timestamp":"2017-10-11T13:01:40.743Z","overlay_id":60436,"acquisition_date":"2017-09-22T20:54:08.270Z","sensor":"WV02","catalog_id":null,"map_id":10752}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.431474,15.45027]},"properties":{"id":"219089-292","tag_id":292,"label":"Flooded / Damaged Building","tagger_id":2349740,"type_id":1955,"score":"1.000000","agreement":36,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/073cd0784ce01deb2832873a2122f932.jpg","timestamp":"2017-10-11T13:01:43.774Z","overlay_id":60436,"acquisition_date":"2017-09-22T20:54:08.270Z","sensor":"WV02","catalog_id":null,"map_id":11840}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.341822,15.42342]},"properties":{"id":"219089-350","tag_id":350,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"0.999627","agreement":10,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/66aece472f8df238c0189f046294f23e.jpg","timestamp":"2017-10-11T13:01:42.648Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":6977}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.27985,15.245364]},"properties":{"id":"219089-359","tag_id":359,"label":"Flooded / Damaged Building","tagger_id":8742443,"type_id":1955,"score":"0.948370","agreement":14,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/2a6eca4e52c24340836293c603edcd8b.jpg","timestamp":"2017-10-11T13:01:47.215Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":6275}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.341597,15.414789]},"properties":{"id":"219089-384","tag_id":384,"label":"Flooded / Damaged Building","tagger_id":4566274,"type_id":1955,"score":"0.999990","agreement":13,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/1600490d7e9efa3d573aea9c516cf2e0.jpg","timestamp":"2017-10-11T13:01:42.648Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":331}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.286416,15.249546]},"properties":{"id":"219089-391","tag_id":391,"label":"Flooded / Damaged Building","tagger_id":8742443,"type_id":1955,"score":"1.000000","agreement":16,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/0236f434f9c1716e2c1d30d33ad9f2e1.jpg","timestamp":"2017-10-11T13:01:39.090Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":2385}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.266836,15.255911]},"properties":{"id":"219089-502","tag_id":502,"label":"Flooded / Damaged Building","tagger_id":8742443,"type_id":1955,"score":"0.999998","agreement":17,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/fe282a4d1637391286ebf0b84d09a338.jpg","timestamp":"2017-10-11T13:01:40.308Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":7221}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.441969,15.438861]},"properties":{"id":"219089-538","tag_id":538,"label":"Flooded / Damaged Building","tagger_id":22905241,"type_id":1955,"score":"1.000000","agreement":43,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/4f7a4e20b5a91821c2b3e65fe42819d1.jpg","timestamp":"2017-10-11T13:01:42.648Z","overlay_id":60436,"acquisition_date":"2017-09-22T20:54:08.270Z","sensor":"WV02","catalog_id":null,"map_id":12697}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.35683,15.322064]},"properties":{"id":"219089-560","tag_id":560,"label":"Flooded / Damaged Building","tagger_id":8742443,"type_id":1955,"score":"1.000000","agreement":40,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/76cc2ac0de044ca01eae9139df1b6037.jpg","timestamp":"2017-10-11T13:01:42.278Z","overlay_id":60435,"acquisition_date":"2017-09-22T20:55:04.632Z","sensor":"WV02","catalog_id":null,"map_id":1985}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.43742,15.443101]},"properties":{"id":"219089-609","tag_id":609,"label":"Flooded / Damaged Building","tagger_id":22905241,"type_id":1955,"score":"1.000000","agreement":19,"chip_size":null,"chip_url":"https://s3.amazonaws.com/explorationlab/chips/61d31afeb10a49faa72537c1f7a7b0d1.jpg","timestamp":"2017-10-11T13:01:41.129Z","overlay_id":60436,"acquisition_date":"2017-09-22T20:54:08.270Z","sensor":"WV02","catalog_id":null,"map_id":8083}}
答案 0 :(得分:1)
坐标嵌套在geometry
元素内。您不需要嵌套循环,只需直接对其进行索引即可。
foreach ($value as $key => $value1) {
$coordinates = $value1['geometry']['coordinates'];
echo "<pre>";
print_r($key);
echo "\n";
print_r($coordinates);
echo "</pre>";
}