我有以下JSON文件:
[
{
"1421999354744": {
"article_id": "213123",
"artfile_status": "",
"process_starttime": "2015\/01\/23 13:19:14",
"process": "Validator",
"process_endtime": "2015\/01\/23 13:19:14",
"process_status": "COMPLETED",
"sub_process_name": "",
"percentage_completed": "100",
"XML_Validity": "false",
"process_type": "AUTO"
}
},
{
"1421999527002": {
"article_id": "213123",
"artfile_status": "",
"process_starttime": "2015\/01\/23 13:22:06",
"process": "Validator",
"process_endtime": "2015\/01\/23 13:22:06",
"process_status": "COMPLETED",
"sub_process_name": "",
"percentage_completed": "100",
"XML_Validity": "false",
"process_type": "AUTO"
}
},
{
"1421999580405": {
"article_id": "213123",
"artfile_status": "",
"process_starttime": "2015\/01\/23 13:23:00",
"process": "Validator",
"process_endtime": "2015\/01\/23 13:23:00",
"process_status": "COMPLETED",
"sub_process_name": "",
"percentage_completed": "100",
"XML_Validity": "false",
"process_type": "AUTO"
}
}
]
我需要在上面获得article_id
的值。我试图阅读多维度,但显示错误。
我的代码如下:
foreach ($response as $key => $value) {
$t = $response[$i];
foreach ($t as $key1 => $value2) {
echo $t[$j]['article_id'];
$j++;
}
$i++;
}
第一个数组值将是动态的。
任何帮助将不胜感激!
答案 0 :(得分:0)
您根本不需要计数器(在您的情况下为$i
,$j
)。您可以通过迭代数组并直接从迭代器的当前值中提取数据来从数组中提取值:
foreach ($response as $key => $value) {
// Get the first value of the sub-array array,
// which is actually the array you want to extract values from
$value = current($value);
// Print out the article id value
// if your json has been decoded as an array use $value['article_id']
echo $value->article_id;
}