在this问题中,我帮助简化并形成了有效的复杂JSON POST请求。但是,我现在遇到了一些服务器端的奇怪行为。
function postTour(){
$post = json_decode($_POST['json'];
$success = false;
for ($i=0; $i<count($post); $i++){
$filename = $post[i]['location']['filename'];
}
}
这里,$filename
永远不会被初始化,也不会在调试器中显示为变量。 $post
返回格式为
$post[3]
[0] =>
location = [ 5 key/value pairs ]
links = one to n arrays
[1] =>
location = [ 5 key/value pairs],
links = one to n arrays
在调试器中,每个最外层数组和位置数组的类型为stdClass
,而links数组的类型为array[n]
。但是,我无法访问$post
内的任何信息。这是为什么?
答案 0 :(得分:4)
尝试将true
作为第二个参数传递给json_decode()
,以便将其转换为实际数组。
$post = json_decode($_POST['json'], true);