日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
遇到一個關(guān)于php7json_decodenull問題!

遇到一個關(guān)于php7 json_decode null問題!

具體問題描述:

1、確認文件無BOM頭

2、嘗試了如下多種方式去除非法字符串,但是仍然輸出NULL

        $some_string = htmlspecialchars_decode($some_string);
        $some_string = preg_replace("/\t/", " ", $some_string);
        $some_string = preg_replace("/\n/", ' ', $some_string);
        $some_string = str_replace("\n", ' ', $some_string);
        $some_string = str_replace ('\n','', $some_string);

3、json_last_error()輸出4,Syntax error, malformed JSON

4、直接輸出字符串,瀏覽器能夠正常解析josn,如下截圖

解決辦法:

因為你的字符串不是標準的JSON字符串, 標準的JSON字符串每個string類型都要用"引起了

測試代碼


結(jié)果

NULL
int(4)
--------分割線--------
array(2) {
  ["status"]=>
  array(2) {
    ["RetCode"]=>
    int(0)
    ["msg"]=>
    string(7) "success"
  }
  ["data"]=>
  array(0) {
  }
}

============== 更新 ==============

經(jīng)過調(diào)試,發(fā)現(xiàn)是 BOM 引起的,下面是解決方案

$dataString = $merchant_arr['data'];
$A = substr($dataString, 0, 1);
$B = substr($dataString, 1, 1);
$C = substr($dataString, 2, 1);
if ((ord($A) == 239) && (ord($B) == 187) && (ord($C) == 191)) {
    $dataString = substr($dataString, 3);
}
$dataArray = json_decode($dataString, true);

新聞標題:遇到一個關(guān)于php7json_decodenull問題!
文章路徑:http://www.5511xx.com/article/cdheidg.html