How to take data out of JSON and put it in a new group
The JSON data is as follows:
{
"Communitymodel": [
{
"UUID": "Xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",
"CommunityName": "Green Garden",
"Communityaddress": "XXXX203 number",
"Longitude": "12.33333333",
"Latitude": "143.1121222",
"Form": "Commercial housing",
"Buildingnum": "100",
"Ownernum": "1800",
"Carportnum": "1800"
},
{
"UUID": "Xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",
"CommunityName": "Green Garden 2",
"Communityaddress": "No. No. 203 XX Road",
"Longitude": "12.33333333",
"Latitude": "143.1121222",
"Form": "Commercial housing",
"Buildingnum": "100",
"Ownernum": "1800",
"Carportnum": "1800"
}
]
}
Obtained by PHP, requires that the UUID and communityname in the JSON be returned in a new array $arr.
My code is as follows:
$url _get = ' http://api.com:90/1.php ';
$json =json_decode ($this->curlget ($url _get));
foreach ($json as $jsonvalue)
{
。。。。 How to write here
Dump ($jsonvalue);
}
------Solution--------------------
It's weird, actually, the key name is blank at both ends.
$s =<<< JSON
{
"Communitymodel": [
{
"UUID": "Xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",
"CommunityName": "Green Garden",
"Communityaddress": "XXXX203 number",
"Longitude": "12.33333333",
"Latitude": "143.1121222",
"Form": "Commercial housing",
"Buildingnum": "100",
"Ownernum": "1800",
"Carportnum": "1800"
},
{
"UUID": "Xxxxxx-xxxxxx-xxxxxxx-xxxxxx2",
"CommunityName": "Green Garden 2",
"Communityaddress": "No. No. 203 XX Road",
"Longitude": "12.33333333",
"Latitude": "143.1121222",
"Form": "Commercial housing",
"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