2013-01-31 2 views
0

Je renvoie une réponse html dans un champ d'objet json $o->sHtml. Le test sHtml est d'environ 13000 caractères et après json_encode son $o->sHtml = null. Une idée pourquoi?json_encode avec grandes chaînes

+0

Comment allez-vous déclarez? Pouvez-vous le montrer? –

Répondre

3

Le codage JSON fonctionne uniquement avec les données codées UTF-8. vérifier si vos données d'entrée est UTF8 ou non

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

Ce sont les erreurs possibles

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

+0

merci l'homme! c'était ça ! – StPiere

+0

vous êtes les bienvenus! Acceptez la réponse si c'est utile! :) – Venu

Questions connexes