Heim > Backend-Entwicklung > PHP-Tutorial > 怎么死都打不开json的数据啊_(:з」∠)_

怎么死都打不开json的数据啊_(:з」∠)_

WBOY
Freigeben: 2016-06-20 12:27:23
Original
1033 Leute haben es durchsucht

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)));
Nach dem Login kopieren
Nach dem Login kopieren
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        ))
Nach dem Login kopieren
Nach dem Login kopieren

弄个 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)));
Nach dem Login kopieren
Nach dem Login kopieren
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        ))
Nach dem Login kopieren
Nach dem Login kopieren

好像真的行了!!!
请问那个substr()的参数为什么是3啊?如果处理其他的json文件也是3吗?还是需要做个判定呢?

utf-8 的BOM 头,是三个字符,所以用 substr 跳过前 3 个字符
既然是要输出 json 那么程序文件要保存为  utf-8 无 BOM 格式 

多谢版主!!

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage