json_en code PHP结果为NULL? [英] json_encode php result is NULL?

查看:129
本文介绍了json_en code PHP结果为NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   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 nulling 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)

相关阅读:<一href="http://stackoverflow.com/questions/4663743/how-to-keep-json-en$c$c-from-dropping-strings-with-invalid-characters">How保持json_en code()跌落无效字符的字符串

这篇关于json_en code PHP结果为NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆