【发布时间】:2013-08-20 17:14:22
【问题描述】:
我在从 JSON 中创建 foreach 循环时遇到问题,我无法从数组中正确获取值,我做错了什么?
JSON:
[
{"Pages":{
"name":"Name 1",
"id":"3342939832994"
}
},
{"Pages":{
"name":"Name 2",
"id":"289051164453763"
}
}
]
PHP:
$json = $_POST['Publish'];
$json = $json->Pages
foreach($json as $key => $items) {
$id = $items->id;
$name = $items->id;
}
【问题讨论】:
-
您忘记
json_decode数据。下一个问题是什么? -
投票关闭,因为“从数组中获取正确的值”不是问题描述。
-
谢谢,我试过 json_decode,但字符串给出了 med "null"