从json提取信息 - 初学者
问题描述:
嗨我无法从此json提取所有变量。谁能帮忙?从json提取信息 - 初学者
{"[email protected]":[{"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 ([[email protected]] => 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的提要。 任何指针或链接将是巨大的感谢 戴夫
答
简单循环例如JSON来访问数据是:
foreach(json_decode($array) as $key => $value) {
print_r($key); // [email protected]
foreach($value as $info) {
print_r($info->action);
print_r($info->timestamp);
print_r($info->url);
print_r($info->ip);
}
}
+0
谢谢我会给它一个去 – 2015-03-25 00:18:59
+0
工作感谢百万 – 2015-03-25 00:34:37
这不是JSON。这是一个普通的数组。 – 2015-03-24 23:50:58
是的,谢谢。这是,但我用json_decode,我会更新问题 – 2015-03-24 23:55:24
'$ newarray ['[email protected]'] [0] ['action'];' – Darren 2015-03-25 00:00:50