PHP json_encode() making data null
I have this code here:
case 'resource_list':
if(file_exists('content.php')){
include('../ajax/content.php');
} else {
die('does not exist');
}
$html = render_content_page($array[1],$array[2开发者_开发技巧]);
$slate = 'info_slate';
$reply_array = array(
'html' => $html,
'slate' => $slate
);
echo json_encode($reply_array);
break;
i have debugged every level right up until json_encode()
is called. But the data i receive back in my ajax is nul for the html key. This code is essentially a copy and paste of another case the just calls a function other than render_content_page()
but that works perfectly fine.
$reply_array var_exports to:
array (
'html' => '<ol>
<li unit="quiz" identifier=""><img src="img/header/notifications.png"/>Fran�ois Vase Volute Krater</li>
</ol>',
'slate' => 'info_slate',
)
My initial thought is that special character in Fran�ois Vase Volute Krater
, as json_encode only works with UTF-8 encoded data.
Try UTF-8 encoding it before JSON encoding it like so:
json_encode(utf8_encode("Fran�ois Vase Volute Krater"));
Maybe problem is with encoding?
As manual states, json_encode()
works only only with utf8 encoded data:
This function only works with UTF-8 encoded data.
http://php.net/json_encode
As documented, json_encode
expects its input text in UTF-8. Most likely, your input (the ç
) is not in UTF-8.
Use utf8_encode
(if you're currently using ISO-8859-1) or mb_convert_encoding
(otherwise) to convert input strings to UTF-8.
精彩评论