how can use php to parse json format?
now I have this link : https://data.tycg.gov.tw/api/v1/rest/dataset/bed8a800-be39-4750-89a6-324b71f5d5fa
I want to parsing this json
{
"identifier": "bed8a800-be39-4750-89a6-324b71f5d5fa",
"categoryCode": [
"e058256f-df7b-4a28-9b4e-6a70b73a0496"
],
"title": "Taipei",
"description": "Information。",
"fieldDescription": "More information",
"type": "Ori",
"organization": "Travel",
"organizationContactName": "Mr.James",
"organizationContactPhone": "0912345678",
"organizationContactEmail": "example@example.com",
"accrualPeriodicity": "Now",
"temporalCoverageFrom": "",
"temporalCoverageTo": "",
"modified": "2021-02-17T02:19:49.000537",
"spatial": "Taipei",
"language": "",
"landingPage": "http://example.com",
"numberOfData": "155",
"distribution": [
{
"resourceID": "bd906b29-9006-40ed-8bd7-67597c2577fc",
"resourceDescription": "",
"format": "JSON",
"resourceModified": "2021-02-17T02:19:49.000537",
"downloadURL": "https://data.tycg.gov.tw/opendata/datalist/datasetMeta/download?id=bed8a800-be39-4750-89a6-324b71f5d5fa&rid=bd906b29-9006-40ed-8bd7-67597c2577fc",
"characterSetCode": "UTF-8"
}
]
}
but, when I use this code, it will get error.
$url="https://data.tycg.gov.tw/api/v1/rest/dataset/bed8a800-be39-4750-89a6-324b71f5d5fa";
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($url, true)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo "$key:\n";
} else {
echo "$key => $val\n";
}
}