如何在PHP中更正json?
在第1页,表单由服务器上的数据保留,在第2页返回数据,但我无法提取它们,我保存在文件中,有数据,如果我不保存,则无法捕获它们如何在PHP中更正json?,php,Php,在第1页,表单由服务器上的数据保留,在第2页返回数据,但我无法提取它们,我保存在文件中,有数据,如果我不保存,则无法捕获它们 $postdata = file_put_contents('file.txt', json_decode(file_get_contents('php://input') 在文件[{“TourDate”:“23.01”,“夜晚”:“7”,“城市”:“\u0428\u0430\u0440\u043c-\u044d\u043b\u044c-\u0428\u0435\u04
$postdata = file_put_contents('file.txt', json_decode(file_get_contents('php://input')
在文件[{“TourDate”:“23.01”,“夜晚”:“7”,“城市”:“\u0428\u0430\u0440\u043c-\u044d\u043b\u044c-\u0428\u0435\u0439\u0445”,“酒店”:“信天翁水蓝度假村沙姆沙伊赫4+*”,“董事会”:“AI”,“住宿”:“1(18+”,“价格”:“836”,“月份”:“01”
我尝试了json_编码,解码,什么都没发生
如何获取数据并使用它们?“在文件中”-在什么文件中?@zerkms的意思可能是“file.txt”,他无法正确读取该文件中的JSON数据?您将三个函数调用打包在一行中,并且不检查其中任何一个的结果。不要将自己的代码视为一个神秘的黑盒子。将
$postdata = file_put_contents('file.txt', json_decode(file_get_contents('php://input');
$tour = json_decode_custom(file_get_contents('file.txt'));
$tour->TourDate; // 23.01
$tour->Nights; // 7
...
function json_decode_custom($json)
{
return json_decode(trim($json, "[]"));
}