2013-01-31 62 views
0

我在json對象字段$o->sHtml中返回一個html響應。帶有大字符串的json_encode

測試sHtml約爲13000個字符,在json_encode之後爲$o->sHtml = null。 任何想法爲什麼?

+0

你是如何聲明?你能證明嗎? –

回答

3

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

+0

謝謝你!就是這樣! – StPiere

+0

不客氣!接受答案,如果它有用! :) – Venu

相關問題