我是 php 新手,我很难从我的 JSON 对象中获取正确的数据。我不想从此JSON 链接获取 series_id、名称、单位和更新
这是示例 JSON:
{
"request":{
"category_id":40445,
"command":"category"
},
"category":{
"category_id":"40445",
"parent_category_id":"40920",
"name":"Btu",
"notes":"",
"childcategories":[
],
"childseries":[
{
"series_id":"SEDS.PATCB.RI.A",
"name":"All petroleum products total consumption, Rhode Island",
"f":"A",
"units":"Billion Btu",
"updated":"22-APR-13 12.40.53 PM"
},
{
"series_id":"SEDS.PATCB.TN.A",
"name":"All petroleum products total consumption, Tennessee",
"f":"A",
"units":"Billion Btu",
"updated":"22-APR-13 12.40.53 PM"
}
]
}
}
到目前为止,这是我的尝试:
<?php
$API_url ='http://api.eia.gov/category/?api_key=FA92066C073D681DD8795C40F72E3B4B&category_id=40445';
$string .= file_get_contents($API_url);// get json content
$json_result = json_decode($string, true);//json decoder
foreach ($json_result as $value) {
foreach ($value as $key => $entry) {
print_r($entry);
}
}
?>
我将如何从数组中获取所有 series_id、名称、单位和更新?