这篇文章将为大家详细讲解有关php程序如何遍历json数据,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
1、json_decode是php5.2.0之后新增的一个PHP内置函数,其作用是对JSON格式的字符串进行编码。
2、接受JSON格式的字符串并且把它转换为PHP变量。
当该参数$assoc为TRUE时,将返回array,否则返回object。
语法规则:
json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
实例
<?php
$str = '{
"10924": {
"id": "10924",
"title": "天津",
"streamline_title": "狗不理",
"unit": "点",
"goods_type": "168",
"goods_type_title": "包子"
},
"10923": {
"id": "10923",
"title": "北京",
"streamline_title": "王府井",
"unit": "点",
"goods_type": "104",
"goods_type_title": "吃货天堂"
},
"11982": {
"id": "11982",
"title": "南京",
"streamline_title": "夫子庙",
"unit": "点",
"goods_type": "351",
"goods_type_title": "灯会"
}
}';
foreach (json_decode($str) as $v)
{
echo "{$v->id} {$v->title}"; //其他的一样的
}
关于“php程序如何遍历json数据”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.py.cn/php/jiaocheng/33160.html