0
我想從使用PHP JsonReader的大型和嵌套JSON文件中提取數據,並將其放入.csv
。我的問題是:使用PHP JsonReader從大型嵌套JSON文件中提取數據
- 打印出來的密鑰與
foo_
一列開始 - 打印出的其他對象的值在嵌套文件
我想要的CSV表this。不知何故,我沒有得到期望的結果,但我知道我有一個想法。這裏是my dummy file。
這裏是我的代碼:
<?php
require_once 'C:/xampp/htdocs/json/pcrov/vendor/autoload.php';
use \pcrov\JsonReader\JsonReader;
ini_set("max_execution_time", 0);
$reader = new JsonReader();
$reader->open("jsonfile.json");
$fo = fopen("csvfile.csv", "w");
fputs($fo, "name, companyID, ultimateHoldingCompany".PHP_EOL);
while ($reader->read(strpos($key, "foo__"))) {
// I want to loop through the key that contains foo_ and print the key name
$companyID = null;
$entityName = null;
$uhc = null;
$companyID = $key
$entityName = $reader->value();
$UltimateHoldingCompany = $reader['ultimateHoldingCompany']['name']-
>value;
fputs($fo,
$entityName.",".$companyID.",".$UltimateHoldingCompany.PHP_EOL);
}
$reader->close();
?>