我有以下json:
{
"data": [
{
"id": "116376655202954/insights/page_impressions_organic/day",
"name": "page_impressions_organic",
"period": "day",
"values": [
{
"value": 13059,
"end_time": "2013-02-22T08:00:00+0000"
},
{
"value": 15223,
"end_time": "2013-02-23T08:00:00+0000"
},
我使用 PHP 来获取以下 foreach 的value
值end_time
:
foreach ($page_impressions_organic['data'] as $page_impression_organic) {
foreach($page_impression_organic['values'] as $key => $page_impression_organic_values) {
$end_time = strval($page_impression_organic_values['end_time']);
$ds = substr($end_time, 0, -14);
$value = intval($page_impression_organic_values['value']);
echo '[\'' . $ds . '\', ' . $value . ']';
}}
一切正常,我的问题是现在我有一个不同的 json:
{
"data": [
{
"id": "116376655202954/insights/page_storytellers_by_story_type/day",
"name": "page_storytellers_by_story_type",
"period": "day",
"values": [
{
"value": {
"fan": 2043,
"page post": 293,
"user post": 5
},
"end_time": "2013-02-22T08:00:00+0000"
},
{
"value": {
"fan": 1085,
"page post": 398,
"user post": 5
},
"end_time": "2013-02-23T08:00:00+0000"
},
而且我无法获得相同的结果,因为value
它是一个数组,我特别需要page post
它的值。我需要保留我的回声具有的形式以用于进一步的范围。我为此做了另一个 foreach:
foreach ($page_talking_abouts['data'] as $page_talking_about) {
foreach($page_talking_about['values'] as $key => $page_talking_about_values) {
foreach($page_talking_about_values['value'] as $page_talking_about_value) {
$end_time = strval($page_talking_about_values['end_time']);
$ds = substr($end_time, 0, -14);
$value = intval($page_talking_about_value['page post']);
echo '[\'' . $ds . '\', ' . $value . ']';
}}}
但$value
每次都是 0... 我必须做什么?