【发布时间】:2018-06-15 09:39:00
【问题描述】:
我的 json 结构如下:
[46] => stdClass Object
(
[task] => stdClass Object
(
[id] => b3:1130806504
[name] => Prezentare Logos
[type] => task
[status] => closed
[iteration] => Creatie si strategie
[number] =>
[dueAt] =>
)
[project] => stdClass Object
(
[id] => b3:7700161
[name] => F.36.35.23.5 Ibalact/Mirdatod
[workspace] => G7
)
[time] => stdClass Object
(
[total] => 10800
[users] => stdClass Object
(
[54928] => 10800
)
)
[estimate] =>
)
[47] => stdClass Object
(
[task] => stdClass Object
(
[id] => b3:1131005900
[name] => Declinari KV
[type] => task
[status] => open
[iteration] => Creatie
[number] =>
[dueAt] =>
)
[project] => stdClass Object
(
[id] => b3:8035237
[name] => F.52.49.27.4 Single Serve
[workspace] => G7
)
[time] => stdClass Object
(
[total] => 28800
[users] => stdClass Object
(
[57889] => 28800
)
)
[estimate] =>
)
如何回显每个项目的名称和每个用户的时间:例如:[57889] => 28800? 这是我迄今为止尝试过的:
$decoded = json_decode($result,true);
echo "<pre>";
print_r($decoded);
//echo $decoded[0]->name;
foreach($decoded as $ar){
foreach($ar->project as $users){
echo $users;
echo "<br>";
}
}
这给了我以下信息:
[id] => b3:7700161
[name] => F.36.35.23.5 Ibalact/Mirdatod
[workspace] => G7
如何只回显每个项目的名称?我做了一个额外的 foreach,我什至做了以下参考: echo $users->name 但它什么也没显示。我错过了一些东西,但我无法弄清楚是什么。任何帮助。
【问题讨论】:
-
首先,您应该向
json_decode()提供第二个参数。将您的行更改为$decoded = json_decode($result,true);,您将得到一个数组而不是stdObject。
标签: php arrays json multidimensional-array