栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用json_decode在PHP中解析JSON对象

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用json_decode在PHP中解析JSON对象

这似乎起作用:

$url = 'http://www.worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710%22';$content = file_get_contents($url);$json = json_depre($content, true);foreach($json['data']['weather'] as $item) {    print $item['date'];    print ' - ';    print $item['weatherDesc'][0]['value'];    print ' - ';    print '<img src="' . $item['weatherIconUrl'][0]['value'] . '" border="0" alt="" />';    print '<br>';}

如果将json_depre的第二个参数设置为true,则会得到一个数组,因此无法使用->语法。我还建议您安装JSONview
Firefox扩展),以便您可以以类似于 Firefox显示XML结构的漂亮格式的树状视图查看生成的json文档。这使事情变得容易得多。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402875.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号