PHP json_encode()使数据空

问题描述:

我有这样的代码在这里:PHP json_encode()使数据空

case 'resource_list': 
     if(file_exists('content.php')){ 
      include('../ajax/content.php'); 
     } else { 
      die('does not exist'); 
     } 
     $html = render_content_page($array[1],$array[2]); 
     $slate = 'info_slate'; 
     $reply_array = array(
      'html' => $html, 
      'slate' => $slate 
     ); 
     echo json_encode($reply_array); 
    break; 

我已经调试各个层面的权利,直到json_encode()被调用。但我收到的数据在我的ajax中是html的密钥。这段代码本质上是另一种情况的复制和粘贴,只是调用除render_content_page()以外的函数,但是它的工作非常好。

$ reply_array var_exports到:

array (
    'html' => '<ol> 
    <li unit="quiz" identifier=""><img src="img/header/notifications.png"/>Fran�ois Vase Volute Krater</li> 
    </ol>', 
    'slate' => 'info_slate', 
) 
+4

相信我,它不是PHP;) – genesis

+2

^多数民众赞成在有帮助的是什么呢?和PHP只是烦人..... – FraserK

+0

你使用什么PHP版本? – genesis

我最初的想法是在Fran�ois Vase Volute Krater特殊字符,如json_encode只用UTF-8编码的数据工作。 JSON之前

尝试UTF-8编码它像这样编码它:

json_encode(utf8_encode("Fran�ois Vase Volute Krater")); 

也许问题是与编码? 作为手册指出,json_encode()作品仅仅与UTF8编码数据:

此功能仅使用UTF-8编码的数据工作的。

http://php.net/json_encode

+0

加快17秒+1 –

documented如,json_encode预计UTF-8其输入文字。很可能,您的输入(ç)不是UTF-8。

使用utf8_encode(如果您目前使用ISO-8859-1)或mb_convert_encoding(否则)输入字符串转换为UTF-8。