关于PHP数组到JSON的序列化,我确实有一个奇怪的问题:
我得到了一个由许多层组成的数组,在一定的大小下,它工作得很好。但是在某些情况下,返回的JSON对象中缺少右大括号。下面是返回的头部。
Date: Fri, 29 Dec 2017 12:42:39 GMT
Server: Apache/2.2.22 (Debian)
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, userid, dealerid
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT
X-Powered-By: PHP/5.4.45
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 8503
X-UA-Compatible: IE=edge
Content-Type: application/json;charset=utf-8该API是使用用于简单REST API的SLIM 3框架构建的。
API上的设置:
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
...
public function listFailedOrders(Request $request, Response $response, array $args) {
$arr = [];
//algorithm to fill array
//verified that the array has data that is not malformed in any way!
$responseData = [];
$responseData['count'] = count($arr);
$responseData['data'] = $arr;
$response = $response->withJson($responseData, 200);
return $response;
}返回数据:
{
"count": "41",
"data": [
{
.... JSON DATA ....
},
{
.... More JSON Data ....
}
]
//Missing End curly Bracket
我使用Insomnia Rest客户端来检查这一点,到目前为止,我对这个问题的唯一解决方案是在接收端添加一个结束的花括号。
TLDR:我将一个大的(不限于到达的对象)序列化为JSON,但是后面的花括号被修剪掉了。问题的根源是什么?
发布于 2019-07-30 15:23:40
这个问题是一个预设的内容长度标题,它切断了最后一个花括号。这是一个严重的错误。
https://stackoverflow.com/questions/48023247
复制相似问题