小编典典

php json_encode返回null

json

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

“,” 2010-06-21/nordic-capital-buys-sic-processing
“,”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]]}

注意完成后字符串中间的null

为什么要这样做,我需要执行什么转义/操纵才能对此进行编码?

我努力了, addslashes


阅读 256

收藏
2020-07-27

共1个答案

小编典典

从手册中:

请注意,如果您尝试对包含非UTF值的数组进行编码,则在结果JSON字符串中将获得空值。您可以使用array_map函数批量编码数组的所有元素:

$encodedArray = array_map(utf8_encode, $myArr);
echo json_encode($encodedArray);
2020-07-27