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();
?>