php json_encode 返回 null
Array
(
[sEcho] => 1
[iTotalRecords] => 7521
[iTotalDisplayRecords] => 1
[aaData] => Array
(
[0] => Array
(
[0] => Nordic Capital Buys SiC Processing
[1] => 2010-06-21/nordic-capital-buys-sic-processing
[2] => PEHub Media
[3] => Business
[4] => completed
[5] => Nordic Capital has acquired a 70% stake in SiC Processing AG, a German industrial recycling company, from Frog Capital. No sale price was disclosed. SiC Processing’s founding family retains a 25% holding, while former lead investor Zouk Ventures retains a 5% stake.
[6] => Admin, China, Frog Capital, Germany, Italy, Iyad Omari, Manufacturing, Norway, PEHub Media, Photovoltaic Wafer Manufacturing, Renewable Energy, Semiconductor, United States
)
)
)
echo json_encode($myArr);
{"sEcho":"1","iTotalRecords":7521,"iTotalDisplayRecords":"1","aaData":[[" Nordic Capital 收购 SiC 加工业务"," 2010-06-21/nordic-capital-buys-sic-processing","PEHub Media","业务","已完成",null, ” 管理员,中国,Frog Capital,德国,意大利,Iyad Omari,制造业,挪威,PEHub Media,光伏晶圆制造,可再生能源,半导体,美国]]}
完成后注意字符串中间的空< /strong>
为什么会这样,我需要执行什么转义/操作才能对其进行编码?
我已经尝试过,addslashes
Array
(
[sEcho] => 1
[iTotalRecords] => 7521
[iTotalDisplayRecords] => 1
[aaData] => Array
(
[0] => Array
(
[0] => Nordic Capital Buys SiC Processing
[1] => 2010-06-21/nordic-capital-buys-sic-processing
[2] => PEHub Media
[3] => Business
[4] => completed
[5] => Nordic Capital has acquired a 70% stake in SiC Processing AG, a German industrial recycling company, from Frog Capital. No sale price was disclosed. SiC Processing’s founding family retains a 25% holding, while former lead investor Zouk Ventures retains a 5% stake.
[6] => Admin, China, Frog Capital, Germany, Italy, Iyad Omari, Manufacturing, Norway, PEHub Media, Photovoltaic Wafer Manufacturing, Renewable Energy, Semiconductor, United States
)
)
)
echo json_encode($myArr);
{"sEcho":"1","iTotalRecords":7521,"iTotalDisplayRecords":"1","aaData":[["
Nordic Capital Buys SiC Processing</a></div>","
2010-06-21/nordic-capital-buys-sic-processing</div>","PEHub Media","Business","completed",null,"
Admin, China, Frog Capital, Germany, Italy, Iyad Omari, Manufacturing, Norway, PEHub Media, Photovoltaic Wafer Manufacturing, Renewable Energy, Semiconductor, United States]]}
Note the null in the middle of the string after completed
Why is this, what escape/manipulation do I need to perform in order to encode this?
I have tried, addslashes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从手册:
From the manual:
实际上它不会返回 null,http://codepad.org/A34KdUf5。
也许您的 PHP 版本不支持 json_encode()。
Actually it doesn't return null, http://codepad.org/A34KdUf5.
Maybe your PHP version doesn't support json_encode().
在 5.2.13 上为我工作。确保您至少使用 PHP 5.2.0 并且 PHP 不是使用 --disable-json 编译的。您可能还想检查是否启用了错误报告(和/或日志记录)。
Works for me on 5.2.13. Ensure you're using at least PHP 5.2.0 and that PHP wasn't compiled with --disable-json. You may also want to check that error reporting (and/or logging) is enabled.
更简单的方法是
$store_name = utf8_encode(name_of_varaible)
但请确保您的字符集是ISO-8859-1。
The simpler way is
$store_name = utf8_encode(name_of_varaible)
but please make sure that your character set isISO-8859-1.