简体   繁体   中英

json_encode with large strings

I'm returning a html response in a json object field $o->sHtml .

The testing sHtml is about 13000 characters and after json_encode its $o->sHtml = null . Any idea why?

Json encode only works with UTF-8 encoded data. check whether your input data is utf8 or not

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

These are the possible errors

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM