0

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?

1
  • How are you declaring that? Can you show it? Commented Jan 31, 2013 at 9:54

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.