How to take data out of JSON and put it in a new group

Source: Internet
Author: User
The JSON data is as follows:
{"    Communitymodel": [        {            "UUID": "Xxxxxx-xxxxxx-xxxxxxx-xxxxxx1",            "CommunityName": "Green Garden",            " Communityaddress ":" XXXX203 ",            " longitude ":" 12.33333333 ",            " Latitude ":" 143.1121222 ",            " Form ":" Commercial housing ", 
   "Buildingnum": "+", "            ownernum": "1800",            "Carportnum": "1800"        },{            "UUID": "Xxxxxx-xxxxxx-xx Xxxxx-xxxxxx2 ",            " CommunityName ":" Green Garden 2 ",            " communityaddress ":" XX road No. 203 ",            " longitude ":" 12.33333333 ",            " Latitude ":" 143.1121222 ",            " Form ":" Commercial housing ",            " Buildingnum ":" The ","            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) { ....                      Here's how to write//dump ($jsonvalue);}


Reply to discussion (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 "," Longitu De ":" 12.33333333 "," Latitude ":" 143.1121222 "," Form ":" Commercial Housing "," buildingnum ":" 100 " , "Ownernum": "1800", "Carportnum": "1800"},{"UUID": "Xxxxxx-xxxxxx-xxxxxx X-xxxxxx2 "," CommunityName ":" Green Garden 2 "," communityaddress ":" XX road No. 203 "," Longitude ":"            12.33333333 "," Latitude ":" 143.1121222 "," Form ":" Commercial Housing "," buildingnum ":" 100 ", "Ownernum": "1800", "Carportnum": "1800"}]}json; $a = Json_decode ($s, 1); foreach ($a [' Commu Nitymodel '] 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);? >
  • Related Article

    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.