可能重复: json_en code为返回NULL?
我有一个奇怪的问题,在PHP json_en code()
。 pretty的简单code:
I'm having a strange problem with json_encode()
in php. Pretty simple code:
$content = json_encode(array('content1' => $arm_length,
'content2' => $body_length));
echo $content;
$ arm_length
和 $ body_length
变量包含的HTML标记两个选择下拉菜单。我的问题是,当它回声
的出这展示的 NULL
为内容1
和内容2
。如果我参加了 json_en code()
的路程,只是的print_r($内容)
它显示所有数据,因为它应该是。
$arm_length
and $body_length
variables contain the HTML markup for two select dropdown menus. My problem is when it echo
's out it show's NULL
for content1
and content2
. If I take the json_encode()
away and just do print_r($content)
it shows all the data as it should be.
有谁知道这里发生了什么?是否有某些数据不能被解析成JSON?我已经做到了这一点,现在使用Ajax / PHP几次,从未发生过任何问题。
Does anyone know what's happening here? Is there certain data that can't be parsed into JSON? I've done this a few times now using Ajax/PHP and never had any problems.
干杯任何帮助与此有关。
Cheers for any help with this.
json_en code()
有包含无效默默空
荷兰国际集团性质(=非UTF-8的(无证)习惯)字符。
json_encode()
has the (undocumented) habit of silently null
ing properties that contain invalid (= non-UTF-8) characters.
请确保您输入的数据是UTF-8 EN codeD,其中的是的该函数的一个记录的需求。
Make sure your input data is UTF-8 encoded, which is a documented requirement of that function.
在出现故障的为en code, json_last_error事件()
的可用于确定错误的确切性质。 (可在PHP 5.3只)
In the event of a failure to encode, json_last_error()
can be used to determine the exact nature of the error. (Available in PHP 5.3 only)
相关阅读:How保持json_en code()跌落无效字符的字符串