下面是 HTTP 请求。我需要从中提取数据 - 一个包含单元格和距离键的数组。
curl http://localhost:80/problem2.php -X POST -H Content-Type:application/json --data-binary "{'cells': [4,8,11,18,19], 'distance': 2}"
但是什么都没有出来,因为数据读取不正确。下面是数据的读取。
$data = json_decode(file_get_contents('php://input'));
已知file_get_contents('php://input')准确地接收给定的数组。为什么json_decode()可能行不通?
JSON 严格规范双引号的使用:
小提琴
假设您有文件
problem2.php并且服务器正在侦听localhost:80而不是在8080任何其他端口上。json_decode返回stdClass类型的对象,您需要访问它排气: