php - 如何在 PHP 中更正 json?
问题描述
在第 1 页,表单由服务器上的数据留下,在第 2 页返回数据,但我无法获取它们,我保存在文件中,有数据,如果我不保存,则无法捕获它们
$postdata = file_put_contents('file.txt', json_decode(file_get_contents('php://input')
并在文件中[{"TourDate": "23.01", "Nights": "7", "City": "\u0428\u0430\u0440\u043c-\u044d\u043b\u044c-\u0428\u0435\u0439\u0445", "Hotel": "ALBATROS AQUA BLU RESORT SHARM EL SHEIKH 4+ *", "Board": "AI", "Accomodation": "1 (18+)", "Price": "836", "Month": "01"}]
我尝试 json_encode,解码,什么也没发生
如何获取数据并使用它们?
解决方案
$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, "[]"));
}
推荐阅读
- reactjs - Google O Auth 在本地服务器上工作,但在 nelify 上部署后没有(每次都调用 onFailure)
- python - 将第二列中的值附加到第一列 Python 的末尾
- android - 自定义 Xamarin Forms 应用程序中选项卡项上的焦点状态外观,Android 实现
- django - 选择过滤器一旦添加到数据库中
- numpy - 如何沿单个 pytorch 张量的维度连接?
- android - 是否可以在 Uiautomator 中不用手指向上滑动左右滑动?
- jquery-select2 - 将普通 select 转换为 select2 但保留宽度和类
- r - ggplot2:重新排序图例中的项目
- excel - 使用 VBA 从 Sharepoint 中删除文件
- python - 关联表中有目的的MYSQL重复条目