怎么从Json中取出数据放到一个新组中

WBOY
发布: 2016-06-13 11:59:37
原创
1130 人浏览过

如何从Json中取出数据放到一个新组中
JSON数据如下:

{<br />    "CommunityModel": [<br />        {<br />            " UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",<br />            " CommunityName ": "格林花园",<br />            " CommunityAddress ": "XXXX203号",<br />            " Longitude ": "12.33333333",<br />            " Latitude ": "143.1121222",<br />            " Form ": "商品房",<br />            " BuildingNum ": "100",<br />            " OwnerNum ": "1800",<br />            " CarportNum ": "1800"<br />        },<br />{<br />            " UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",<br />            " CommunityName ": "格林花园2",<br />            " CommunityAddress ": "XX路203号",<br />            " Longitude ": "12.33333333",<br />            " Latitude ": "143.1121222",<br />            " Form ": "商品房",<br />            " BuildingNum ": "100",<br />            " OwnerNum ": "1800",<br />            " CarportNum ": "1800"<br />        }<br />    ]<br />}
登录后复制

通过PHP获取,要求获取JSON中UUID和CommunityName放到一个新数组$arr中返回。

我的代码如下:
		<br />                $url_get ='http://api.com:90/1.php';<br />		$json=json_decode($this->curlGet($url_get));<br />		foreach($json as $jsonvalue)<br />		{<br />                      。。。。这里该如何写<br />	//		dump($jsonvalue);<br />		}
登录后复制

------解决方案--------------------
好奇怪,居然键名两端是空格
$s =<<< JSON
{<br /> "CommunityModel": [<br /> {<br /> " UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",<br /> " CommunityName ": "格林花园",<br /> " CommunityAddress ": "XXXX203号",<br /> " Longitude ": "12.33333333",<br /> " Latitude ": "143.1121222",<br /> " Form ": "商品房",<br /> " BuildingNum ": "100",<br /> " OwnerNum ": "1800",<br /> " CarportNum ": "1800"<br /> },<br />{<br /> " UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",<br /> " CommunityName ": "格林花园2",<br /> " CommunityAddress ": "XX路203号",<br /> " Longitude ": "12.33333333",<br /> " Latitude ": "143.1121222",<br /> " Form ": "商品房",<br /> " BuildingNum ": "100",<br /> " OwnerNum ": "1800",<br /> " CarportNum ": "1800"<br /> }<br /> ]<br />}
JSON;
$a = json_decode($s, 1);
foreach($a['CommunityModel'] as $v) {
$arr[] = array('UUID' => $v[' UUID '], 'CommunityName' => $v[' CommunityName ']);
}
print_r($arr);
登录后复制

Array<br>(<br>    [0] => Array<br>        (<br>            [UUID] => xxxxxx-xxxxxx-xxxxxxx-xxxxxx1<div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板