Maison > Article > développement back-end > 怎么从Json中取出数据放到一个新组中
如何从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 />}
<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>