欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-13 19:44:44
...
如何从Json中取出数据放到一个新组中
JSON数据如下:
{
"CommunityModel": [
{
" UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",
" CommunityName ": "格林花园",
" CommunityAddress ": "XXXX203号",
" Longitude ": "12.33333333",
" Latitude ": "143.1121222",
" Form ": "商品房",
" BuildingNum ": "100",
" OwnerNum ": "1800",
" CarportNum ": "1800"
},
{
" UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",
" CommunityName ": "格林花园2",
" CommunityAddress ": "XX路203号",
" Longitude ": "12.33333333",
" Latitude ": "143.1121222",
" Form ": "商品房",
" BuildingNum ": "100",
" OwnerNum ": "1800",
" CarportNum ": "1800"
}
]
}

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

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

------解决方案--------------------
好奇怪,居然键名两端是空格
$s ={
"CommunityModel": [
{
" UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",
" CommunityName ": "格林花园",
" CommunityAddress ": "XXXX203号",
" Longitude ": "12.33333333",
" Latitude ": "143.1121222",
" Form ": "商品房",
" BuildingNum ": "100",
" OwnerNum ": "1800",
" CarportNum ": "1800"
},
{
" UUID ": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",
" CommunityName ": "格林花园2",
" CommunityAddress ": "XX路203号",
" Longitude ": "12.33333333",
" Latitude ": "143.1121222",
" Form ": "商品房",
" BuildingNum ": "100",
" OwnerNum ": "1800",
" CarportNum ": "1800"
}
]
}
JSON;
$a = json_decode($s, 1);
foreach($a['CommunityModel'] as $v) {
$arr[] = array('UUID' => $v[' UUID '], 'CommunityName' => $v[' CommunityName ']);
}
print_r($arr);
Array
(
[0] => Array
(
[UUID] => xxxxxx-xxxxxx-xxxxxxx-xxxxxx1
怎么从Json中取出数据放到一个新组中

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频