189 8069 5689

phpjson循环数据,phpjson数组

Php json循环解析

json_encode(),转换成json格式

定制网站建设可以根据自己的需求进行定制,网站制作、成都网站设计构思过程中功能建设理应排到主要部位公司网站制作、成都网站设计的运用实际效果公司网站制作网站建立与制做的实际意义

json_decode(),将json转换成对象,第二个参数为true时就是转换成数组

php循环读取json

?php

$str = '[{"name":"北京","city":[{"name":"北京","area":["东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","门头沟区","房山区","通州区","顺义区","昌平区","大兴区","平谷区","怀柔区","密云县","延庆县"]}]},{"name":"天津","city":[{"name":"天津","area":["和平区","河东区","河西区","南开区","河北区","红桥区","塘沽区","汉沽区","大港区","东丽区","西青区","津南区","北辰区","武清区","宝坻区","宁河县","静海县","蓟 县"]}]}]';

$provinces = json_decode($str, true);

foreach($provinces as $province){

echo $province['name'], 'br/';

foreach($province['city'] as $city){

echo '--', $city['name'], 'br/';

foreach($city['area'] as $area){

echo '----', $area, 'br/';

}

}

}

exit;

php 循环遍历json数据

$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里面的数据,大神们帮帮忙啊

$str = '{"queryString":"select id , name from user LIMIT 0, 30 ","data":[{"0":"1","id":"1","1":"aa","name":"aa"},{"0":"2","id":"2","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"3","id":"3","1":"\u5c0f\u4f19\u4f34","name":"\u5c0f\u4f19\u4f34"},{"0":"4","id":"4","1":"44","name":"44"},{"0":"5","id":"5","1":"","name":""},{"0":"6","id":"6","1":"","name":""},{"0":"7","id":"7","1":"","name":""},{"0":"8","id":"8","1":"","name":""},{"0":"9","id":"9","1":"","name":""},{"0":"10","id":"10","1":"jiejie","name":"jiejie"},{"0":"11","id":"11","1":"jiejie","name":"jiejie"}]}';

foreach (json_decode($str) as $v)

{

if(is_array($v))

{

foreach($v as $value)

{

echo "当前的name 为: {$value-name} id : {$value-id}";

}

}

}

中文不管 你取得是对应的name值

PHP循环读取JSON

首先你要把JSON数据转成数组,因为在php中JSON就是一个字符串。

$jsonData = '{"list": [{

"goodsid": 4290,

"post": [{

"param": "uin",

"name": "账号"

}, {

"param": "goodsid",

"name": "商品ID"

}, {

"param": "number",

"name": "下单数量"

}]

}, ';

// 你的JSON数据有点乱,我复制的可能不对

$aryData = json_decode($jsonData, true);   // 转码为数组

var_dump($aryData);  // 打印

foreach ($aryData as $item) {

var_dump($item);   // 打印每个条目

}

php 循环输出 json 数组

?php

$Tdata='[{"A_Name":"a1","ICNo":"","A_ContNo":"","A_QQNo":""},{"A_Name":"a2","ICNo":"","A_ContNo":"","A_QQNo":""},{"A_Name":"a3","ICNo":"","A_ContNo":"","A_QQNo":""}]';

$arr=json_decode($Tdata,true);

//var_dump($arr);

echo stripcslashes ($arr[0][A_Name]);

?

上面的方法可以打印输出,json_decode($Tdata)输出的结果是一个对应,而json_decode($Tdata,true)输出的是一个数组


网站栏目:phpjson循环数据,phpjson数组
文章源于:http://jkwzsj.com/article/hsieoh.html

其他资讯