Re: [請益] JSON編碼"{"編碼有問題

作者: wild0921 (我要幸福)   2014-10-27 11:48:40
※ 引述《wild0921 (我要幸福)》之銘言:
: 想要請問各位PHP大人,
: 我日前建立一個webservice, 發生一個問題,
: 我試用php 5.3.2 版本
: 建立一個array 用json_encode 產生 json string
: 讓其它網頁去接,
: echo 出來 畫面看起來是對的, 但是用json_decode 卻發生問題,
: 檢查發現主要原因, 是json string 一開始的 "{" 編碼有問題, 造成無法轉變成Object,
: 但我在webservice 那一頁自己 json_encode 再 json_decode 卻可以轉成Object
: 想要請問一下, 有沒有人碰過這種問題, 是用什麼方法解決?
: 感謝......
有用nodepad++檢查過, 檔案是utf-8 無Bom檔頭
產json那一個檔案也是utf-8 無Bom檔頭
A.php 網頁內容(撈json的網頁):
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $str_url);
curl_setopt($ch, CURLOPT_POST, true); // 啟用POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $_GET);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, '帳號:密碼');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
$output = curl_exec($ch);
B.php 網頁內容(產json string 的網頁)
die(json_encode($array));
A.php的部分code是我用curl撈資料的方式,
不過那邊json_decode($output); dump 出來是null,
檢查之後 原因是json格式有問題,
我把所有程式碼, 產新的檔案在重新上傳,
有改善的是在B.php 那一頁dump出來, string檢查結果格式是 通過 的
但是在A.php var_dump($output); 貼到檢查json網頁
格式就會錯誤, 死在第一個大括號
所以想要請問有沒有人遇到過一樣的狀況, 然後提供一下解決方法?
作者: shadowjohn (轉角遇到愛)   2014-10-27 12:31:00
json檔丟出來大家看看
作者: MOONRAKER (㊣牛鶴鰻毛人)   2014-10-27 14:16:00
弄個hex editor卡實在

Links booklink

Contact Us: admin [ a t ] ucptt.com