douqian5553 2012-12-17 13:49
浏览 308
已采纳

解码JSON字符串时偶尔会出错

I have two different servers.

In the first one, my development server, everything works as they should. On the second one, my production server, I get a couple of errors I don't know how to address.

On the latter, I keep getting an error while json_decode'ing a string. When trying to pinpoint the error, I found the below:

On my development server, when I var_dump the POST data, I get:

'data' =>
    string(96) "{"id":null,"codigo":55,"nome":"testa","coordenador":"testa","financiadora":"testa","ativo":true}"

Whereas on my production server, I get:

["data"]=>
    string(113) "{\"id\":null,\"codigo\":4,\"nome\":\"teste\",\"coordenador\":\"teste\",\"financiadora\":\"teste\",\"ativo\":true}"

}

I could probably strip the backslashes in my production server, but I don't want to have two different codes. I also don't understand why it's happening.

Is it an Apache/PHP configuration issue? How do I address that?

Exact same code, exact same database in both servers.

  • 写回答

1条回答 默认 最新

  • doupa2871 2012-12-17 13:52
    关注

    Sounds like your production server has Magic Quotes enabled. Turn it off and the problem should disappear.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?