dqgo99177 2017-08-14 13:29
浏览 134

JMS序列化程序返回格式错误的JSON

As title says, I have a problem with JMS serializer running on Symfony 2.7 which returns a malformed JSON. This happens only when database becomes bigger.

I made a simple function which returns the whole database serialized in JSON, sometimes is useful for me to check some data.

Basically I have this function

function asJson($serializationGroup = null)

{
    $serializer = SerializerBuilder::create()->build();

    $serGroups = array('Default');
    if (is_string($serializationGroup)) {
        $serGroups[] = $serializationGroup;
    }
    if (is_array($serializationGroup)) {
        foreach($serializationGroup as $sg) $serGroups[] = $sg;
    }

    $serializationContext = SerializationContext::create()->setGroups($serGroups);
    $serializationContext->setSerializeNull(true);
    return $serializer->serialize($this, 'json', $serializationContext);
}

which returns a JSON containing data associated to given serialization groups. Then I call it from a Controller giving all my serialization groups in order to serialize the entire db.

But, as I said, when my db becomes bigger I get a malformed JSON. Moreover the error is always different

SyntaxError: JSON.parse: expected ':' after property name in object at line 1 column 182085 of the JSON data

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 367466 of the JSON data

SyntaxError: JSON.parse: expected ':' after property name in object at line 1 column 1158 of the JSON data

I tried to analyze the JSON and I noticed that it is totally corrupted after the error line.. Something like:

"commands_deletedse," <-- here starts the error, the rest is malformed
active ":true,"
readonly ":false,"
running ":false,"
...

UPDATE

It seems to work on another PC having MySQL 5.7 while the bug is present on another PC having MySQL 5.5. I don't know if it has something to do with..


UPDATE 2

It seems to work on the same PC but from Symfony command, hence I would say it has something to do with nginx configuration. In fact I even noticed that calling it from website works 1/10 time, so I would say the error comes from something like a timeout configuration or so. I use nginx + php-fpm.


UPDATE 3

I tried to starting the Symfony internal webserver and then call the controller function but I got the same error. I'm starting have no idea about what should I test..

Any thought?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)