How to extract data from Json and put it in a new group

Source: Internet
Author: User
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);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.