怎麼死都打不開json的資料啊_(:з」∠)_

來源:互聯網
上載者:User
http://202.103.244.125/catst.php
如上,剛接觸PHP被這弄得好焦灼!json_decode出來的永遠都是null啊!!!網上的方法也都試了,求大神幫忙


回複討論(解決方案)

我就不相信你都試了

$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array(    [0] => stdClass Object        (            [menutype] => A            [groupx] => 0            [titleng] => 涼菜             [titlech] => Cold Dish        )    [1] => stdClass Object        (            [menutype] => A            [groupx] => 1            [titleng] => 湯 粥            [titlech] => Soup Porrdg        )    [2] => stdClass Object        (            [menutype] => A            [groupx] => 2            [titleng] => 燙菜            [titlech] => Hot food        )    [3] => stdClass Object        (            [menutype] => A            [groupx] => 3            [titleng] => 素菜            [titlech] => Veget -able        )    [4] => stdClass Object        (            [menutype] => A            [groupx] => 4            [titleng] => 主食            [titlech] => Main Food        )    [5] => stdClass Object        (            [menutype] => A            [groupx] => 5            [titleng] => 烤魚 啤酒魚            [titlech] => 烤魚 啤酒魚        )    [6] => stdClass Object        (            [menutype] => A            [groupx] => 6            [titleng] => 幹鍋 湯鍋            [titlech] => Gangou Hotpot        )    [7] => stdClass Object        (            [menutype] => A            [groupx] => 7            [titleng] => 鐵板 煲仔            [titlech] => Sheet Hotpot        )    [8] => stdClass Object        (            [menutype] => A            [groupx] => 8            [titleng] => 砂鍋            [titlech] => Sha Guo        )    [9] => stdClass Object        (            [menutype] => A            [groupx] => 9            [titleng] =>             [titlech] =>         )    [10] => stdClass Object        (            [menutype] => A            [groupx] => 10            [titleng] => 特別 推薦            [titlech] => Special Food        )    [11] => stdClass Object        (            [menutype] => A            [groupx] => 11            [titleng] => 十八釀            [titlech] => 十八釀        )    [12] => stdClass Object        (            [menutype] => A            [groupx] => 12            [titleng] => 飲料 茶            [titlech] => Drink Tea        )    [13] => stdClass Object        (            [menutype] => A            [groupx] => 13            [titleng] => 其他 自訂            [titlech] => 其他 自訂        )    [14] => stdClass Object        (            [menutype] => A            [groupx] => 14            [titleng] => 白酒 啤酒            [titlech] => Wine Beer        ))

弄個 BOM 頭害自己

http://202.103.244.125/catst.php
如上,剛接觸PHP被這弄得好焦灼!json_decode出來的永遠都是null啊!!!網上的方法也都試了,求大神幫忙


正解

我就不相信你都試了

$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array(    [0] => stdClass Object        (            [menutype] => A            [groupx] => 0            [titleng] => 涼菜             [titlech] => Cold Dish        )    [1] => stdClass Object        (            [menutype] => A            [groupx] => 1            [titleng] => 湯 粥            [titlech] => Soup Porrdg        )    [2] => stdClass Object        (            [menutype] => A            [groupx] => 2            [titleng] => 燙菜            [titlech] => Hot food        )    [3] => stdClass Object        (            [menutype] => A            [groupx] => 3            [titleng] => 素菜            [titlech] => Veget -able        )    [4] => stdClass Object        (            [menutype] => A            [groupx] => 4            [titleng] => 主食            [titlech] => Main Food        )    [5] => stdClass Object        (            [menutype] => A            [groupx] => 5            [titleng] => 烤魚 啤酒魚            [titlech] => 烤魚 啤酒魚        )    [6] => stdClass Object        (            [menutype] => A            [groupx] => 6            [titleng] => 幹鍋 湯鍋            [titlech] => Gangou Hotpot        )    [7] => stdClass Object        (            [menutype] => A            [groupx] => 7            [titleng] => 鐵板 煲仔            [titlech] => Sheet Hotpot        )    [8] => stdClass Object        (            [menutype] => A            [groupx] => 8            [titleng] => 砂鍋            [titlech] => Sha Guo        )    [9] => stdClass Object        (            [menutype] => A            [groupx] => 9            [titleng] =>             [titlech] =>         )    [10] => stdClass Object        (            [menutype] => A            [groupx] => 10            [titleng] => 特別 推薦            [titlech] => Special Food        )    [11] => stdClass Object        (            [menutype] => A            [groupx] => 11            [titleng] => 十八釀            [titlech] => 十八釀        )    [12] => stdClass Object        (            [menutype] => A            [groupx] => 12            [titleng] => 飲料 茶            [titlech] => Drink Tea        )    [13] => stdClass Object        (            [menutype] => A            [groupx] => 13            [titleng] => 其他 自訂            [titlech] => 其他 自訂        )    [14] => stdClass Object        (            [menutype] => A            [groupx] => 14            [titleng] => 白酒 啤酒            [titlech] => Wine Beer        ))

好像真的行了!!!
請問那個substr()的參數為什麼是3啊?如果處理其他的json檔案也是3嗎?還是需要做個判定呢?

utf-8 的BOM 頭,是三個字元,所以用 substr 跳過前 3 個字元
既然是要輸出 json 那麼程式檔案要儲存為 utf-8 無 BOM 格式

多謝版主!!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.