php - 在 Laravel - php 中使用 json_encode() 将收集和数组数据编码为 json 有什么区别?
问题描述
尝试在 laravel - php 中对 collect() 和 array() 类型的一些数据进行 json_encode 时,返回类似的 json 对象。在解码(python - 第三方 API)它区分什么?
但是在编码为json之后,两者看起来都一样
{"type":"collection","data":[{"id":3,"id_ref":32},{"id":4,"id_ref":43}]}
{"type":"array","data":[{"id":3,"id_ref":32},{"id":4,"id_ref":43}]}
编码代码:
json_encode(['type'=>'collection','data'=>collect($array)])
json_encode(['type'=>'array','data'=>$array])
解决方案
推荐阅读
- python - 使用 PyTest 进行测试时如何在后台启动 Uvicorn + FastAPI
- sql-server - SQL OLEDB 使用 TLS 1.2 失败
- laravel - 在 Auth::check() 之前,我可以在哪里以及如何设置用户对某些功能或页面的访问权限
- oracle-apex - Oracle Apex 19.1 类图表 100% 区域宽度
- mysql - 无法使用 AWSAuthenticationPlugin 和 terraform 创建 mysql 用户
- angular - 如何将 webapi windows 身份验证与 Angular 应用程序一起使用
- reactjs - Nginx在动态根目录上找不到文件
- java - JavaFX 缺少 Legend 类
- excel - 如何根据范围将多个单元格值作为注释分配给单元格
- c# - 有没有办法在不为每个文件设置“复制到输出目录”属性的情况下“复制如果较新”文件夹中的所有文件?