Php 无法将数组编码为JSON

Php 无法将数组编码为JSON,php,json,Php,Json,我的阵列的var_转储: 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.

我的阵列的var_转储:

   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\u encode($comment)


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

您的评论部分有一个单独的qoutes,请先使用str_replace将其转义,如下所示

$newstring =str_replace('\'', '\\\'', $myString);
然后进行json_编码

json_encode($newstring, true);

您的评论部分中有一个单独的qoutes,首先使用str_replace将其转义,如下所示

$newstring =str_replace('\'', '\\\'', $myString);
然后进行json_编码

json_encode($newstring, true);

最有可能的情况是,您的字符串没有使用UTF-8正确编码,这是预期的。有关更多信息,请参阅


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

最有可能的情况是,您的字符串没有使用UTF-8正确编码,这是预期的。有关更多信息,请参阅


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

可能是单引号,请尝试删除该引号,然后查看它是否有效。如果是,你需要转义它。它可能是一个单引号,试着删除它,看看它是否有效。如果是的话,你需要转义它。+1 json_encode()非常挑剔,有单引号和双引号。有点离题。是否有一个规范化程序--为成功的json编码准备一个字符串??也许htmlentities($string)会有帮助?+1 json_encode()非常挑剔,有单引号和双引号。有点离题。是否有一个规范化程序——为成功的json编码准备一个字符串??也许htmlentities($string)会有所帮助?