How to extract data from Json into a new group JSON data is as follows:
{"CommunityModel": [{"UUID": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1", "CommunityName": "Green Garden", "CommunityAddress": "XXXX203", "longpolling ": "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. 203, XX Road", "longpolling ": "12.33333333", "Latitude": "143.1121222", "Form": "Commercial Housing", "BuildingNum": "100", "OwnerNum": "1800", "CarportNum ": "1800"}]}
Obtain the UUID and CommunityName in JSON in PHP and put them 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 // dump ($ jsonvalue );}
Reply to discussion (solution)
It's strange that there are spaces at both ends of the key name.
$ S = <JSON {"CommunityModel": [{"UUID": "xxxxxx-xxxxxx-xxxxxxx-xxxxxx1", "CommunityName": "Green Garden", "CommunityAddress": "XXXX203 ", "longpolling": "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. 203, XX Road ", "longpolling": "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 [CommunityName] => Green Garden) [1] => Array ([UUID] => xxxxxx-xxxxxx-xxxxxxx-xxxxxx2 [CommunityName] => Green Garden 2 ))
$ Val ['uuid'], 'communityname' => $ val ['communityname']);} print_r ($ arr);?>