【发布时间】:2011-05-09 22:13:25
【问题描述】:
我是第一次使用 JSON 数据,我有一些 PHP 来获取一些 JSON 数据,如下所示(除了 body 中有数百个 measuregrps >)。
$json = file_get_contents("http://wbsapi.withings.net/measure?action=getmeasures");
$json_o = json_decode($json);
例如,我如何使用 foreach 为 type = 1 创建一个一维数组?
{
"status": 0,
"body": {
"updatetime": 1249409679,
"measuregrps": [
{
"grpid": 2909,
"attrib": 0,
"date": 1222930968,
"category": 1,
"measures": [
{
"value": 79300,
"type": 1,
"unit": -3
},
{
"value": 652,
"type": 5,
"unit": -1
},
{
"value": 178,
"type": 6,
"unit": -1
},
{
"value": 14125,
"type": 8,
"unit": -3
}
]
},
{
"grpid": 2908,
"attrib": 0,
"date": 1222930968,
"category": 1,
"measures": [
{
"value": 78010,
"type": 1,
"unit": -3
}
]
},
{
"grpid": 2907,
"attrib": 0,
"date": 1222930968,
"category": 1,
"measures": [
{
"value": 77300,
"type": 1,
"unit": -3
},
{
"value": 678,
"type": 5,
"unit": -1
}
]
},
]
}
}
【问题讨论】:
-
有时候,提问的人比阅读的人更清楚自己的目标。确切地说,输出应该是什么?
array(/* ... */)符号会特别有用。