加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php json_encode返回null

发布时间:2020-12-13 13:50:00 所属栏目:PHP教程 来源:网络整理
导读: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] = compl
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,United States]]}

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

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

我试过,addslashes

从手册:

Note that if you try to encode an
array containing non-utf values,
you’ll get null values in the
resulting JSON string. You can
batch-encode all the elements of an
array with the array_map function:

$encodedArray = array_map(utf8_encode,$myArr);
echo json_encode($encodedArray);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读