0

我在 json 对象字段中返回一个 html 响应$o->sHtml

测试sHtml大约 13000 个字符,之后json_encode$o->sHtml = null. 知道为什么吗?

4

1 回答 1

4

Json 编码仅适用于 UTF-8 编码的数据。检查您的输入数据是否为 ​​utf8

$json  = json_encode($o->sHtml); //or json_encode($o);
$error = json_last_error();
var_dump($json, $error === JSON_ERROR_UTF8);

这些是可能的错误

JSON_ERROR_NONE -   No error has occurred    
JSON_ERROR_DEPTH -  The maximum stack depth has been exceeded    
JSON_ERROR_STATE_MISMATCH - Invalid or malformed JSON    
JSON_ERROR_CTRL_CHAR -Control character error, possibly incorrectly encoded  
JSON_ERROR_SYNTAX - Syntax error     
JSON_ERROR_UTF8 -   Malformed UTF-8 characters, possibly incorrectly encoded

参考:http ://www.php.net/manual/en/function.json-last-error.php

于 2013-01-31T09:59:06.567 回答