ホームページ > バックエンド開発 > PHPチュートリアル > jsonデータが開けないのですが_(:з」∠)_

jsonデータが開けないのですが_(:з」∠)_

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
リリース: 2016-06-20 12:27:23
オリジナル
1056 人が閲覧しました

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 ヘッダーは 3 文字なので、substr を使用して最初の 3 文字をスキップします
json を出力するため、プログラムファイルは なしで utf-8 として保存する必要がありますBOM 形式

モデレーターありがとうございます。 !

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート