0

我的数组的 var_dump:

   array(10) { ["idcomment"]=> string(2) "26" [0]=> string(2) "26" ["parentcomment_id"]=> string(2) "25" [1]=> string(2) "25" ["comment"]=> string(531) "damnJoin Dev Center and publish your app in the Windows Phone Store. GET SDK GET SDK Download the tools to build great Windows Phone apps. VIEW SAMPLES VIEW SAMPLES View code samples from Microsoft and the community to get started. Develop games for Windows PhoneThere has never been a better time to develop games for Windows Phone. We’ve made it simple for you to get started with support for native code and in-app purchase. One third of all Windows Phone downloads and 60 percent of revenue are from games – get started now." [2]=> string(531) "damnJoin Dev Center and publish your app in the Windows Phone Store. GET SDK GET SDK Download the tools to build great Windows Phone apps. VIEW SAMPLES VIEW SAMPLES View code samples from Microsoft and the community to get started. Develop games for Windows PhoneThere has never been a better time to develop games for Windows Phone. We’ve made it simple for you to get started with support for native code and in-app purchase. One third of all Windows Phone downloads and 60 percent of revenue are from games – get started now." ["dt"]=> string(19) "2013-04-29 21:36:29" [3]=> string(19) "2013-04-29 21:36:29" ["iduser"]=> string(1) "1" [4]=> string(1) "1" } 

结果json_encode($comment)如下:

{"idcomment":"26","0":"26","parentcomment_id":"25","1":"25","comment":null,"2":null,"dt":"2013-04-29 21:36:29","3":"2013-04-29 21:36:29","iduser":"1","4":"1"} 

我缺少comment字段。它适用于较短的字符串......我做错了什么?

4

2 回答 2

3

您的评论部分中有一个 qoutes 首先使用 str_replace 像这样将其转义

$newstring =str_replace('\'', '\\\'', $myString);

然后做 json_encode

json_encode($newstring, true);
于 2013-04-30T04:53:46.560 回答
3

很可能,您的字符串未使用json_encode预期的 UTF-8 正确编码。有关详细信息,请始终查看UTF-8

如果您有使用其他编码(例如Windows-1252)对现有数据进行编码,请使用诸如mb_convert_encoding在 JSON 编码之前将其转换为 UTF-8 的函数。

于 2013-04-30T05:01:17.567 回答