json_decode返回json字符串而不是数组

Nad*_*kar 2 php ajax json

<?php

$json=file_get_contents('php://input',true);
$data = json_decode($json, true);

print_r($data);
?>
Run Code Online (Sandbox Code Playgroud)

给定的输出是 {"EventTitle":"Game","EventBody":"body","EventDate":"20 November, 2016","EventType":"party"}

杰森发布的数据是:

 {"EventTitle":"Game","EventBody":"body","EventDate":"20 November, 2016","EventType":"party"}
Run Code Online (Sandbox Code Playgroud)

将JSON数据写入变量并将其传递给json_decode可以正常工作,但是从“ php:// input”发布相同的数据将返回JSON数据而不是关联数组。

Don*_*nic 5

看来@tkausl是正确的。您收到的JSON已被双重编码。由于它是经过双重编码的,因此临时解决方案是对其进行双重解码。

$data = json_decode(json_decode($json), true);
Run Code Online (Sandbox Code Playgroud)

但是真正的解决方案是弄清楚为什么要这样开始并进行修复(如果要修复的话)。