久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

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

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

      具體問題描述:

      1、確認(rèn)文件無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,如下截圖

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

      解決辦法:

      因為你的字符串不是標(biāo)準(zhǔn)的JSON字符串, 標(biāo)準(zhǔn)的JSON字符串每個string類型都要用"引起了

      測試代碼

      <?php  $jsonStr1 = '{status: {RetCode:0, msg: "success"}, data: {}}'; var_dump(json_decode($jsonStr1, true)); var_dump(json_last_error()); echo "--------分割線--------".PHP_EOL; $jsonStr2 = '{"status": {"RetCode":0, "msg": "success"}, "data": {}}'; var_dump(json_decode($jsonStr2, true));

      結(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);

      推薦學(xué)習(xí):《PHP7教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號