嗨,我无法从这个json中提取所有变量。有人可以帮忙吗?
{"name@email.com":[{"action":"open","timestamp":"2015-03-24 17:31:02","url":null,"ip":"212.126.37.01"},{"action":"open","timestamp":"2015-03-24 17:31:03","url":null,"ip":"212.126.37.01"}]}
我使用了json_decode并得到了这个:
Array ( [name@email.com] => Array ( [0] => Array ( [action] => open [timestamp] => 2015-03-24 17:31:02 [url] => [ip] => 212.126.37.01 ) [1] => Array ( [action] => open [timestamp] => 2015-03-24 17:31:03 [url] => [ip] => 212.126.37.01 ) ) )
我试过了:
$newarray = json_decode($array, true);
echo $newarray[0]['action'];
但没有运气
我想要提取电子邮件,因为有很多其他json数据包含不同的电子邮件。为了给出一些见解,这是来自Mailchimp export api的一个feed。 任何指针或链接都会非常感谢 戴夫
答案 0 :(得分:1)
在示例json中访问数据的简单循环是:
foreach( json_decode( $array ) as $key => $value ) {
print_r( $key ); // name@email.com
foreach( $value as $info ) {
print_r( $info->action );
print_r( $info->timestamp );
print_r( $info->url );
print_r( $info->ip );
}
}