Array
(
[0] => Job
[1] =>
[2] => Array
(
[0] => stdClass Object
(
[AppDataId] => 16368
[JobTitle] => Sigma Six Black Belt/Lean Administration Consultant
[Abstract] => Sigma Six Black Belt/Lean Administration Consultan ... - open
)
[1] => stdClass Object
(
[AppDataId] => 16367
[JobTitle] => General Manager (Power Generation)
[Abstract] => General Manager (Power Generation) - Botswana
)
[2] => stdClass Object
(
[AppDataId] => 16366
[JobTitle] => Resident Engineer - Mpumalanga
[Abstract] => Resident Engineer - Mpumalanga - Mpumalanga
)
)
[3] =>
)
我需要将它变成PHP数组并列出所有JobTitle或任何其他字段
我已经完成了这个但是我无法弄清楚如何首先只访问JobTitle,然后再列出所有这些。 $ json_url是输出上述信息的json文件的实际url。
$json1 = file_get_contents($json_url);
$array = json_decode($json1);
echo "<pre>";
print_r($array);
echo "</pre>";
$strJob=array();
foreach ($array as $value) {
$strJob[2][1]=$value->JobTitle;
}
echo '<br/>';
print_r($strJob);
echo '<br/>';
答案 0 :(得分:1)
您应该使用以下语法:
if(isset($array[2])) {
foreach ($array[2] as $value) {
echo 'JobTitle ->' . $value->JobTitle . '<br/>';
echo 'AppDataId ->' . $value->AppDataId. '<br/>';
}
}