简体   繁体   中英

Parsing json to php in httpful from laravel eloquent

I have this JSON data. How do you parse this with httpful? or in just plain PHP?

I want to be able to display something like

Name: John Doe |
Phone: 0987654321 |
Email: john@doe.com |
Friend's Name: Jane Doe

Name: Rye Dale | 
Phone: 0987654321 | 
Email: rye@dale.com | 
Friend's Name: John Dale

How do I properly parse this?

"group":[
    {
        "id":"1",
        "firstName":"John",
        "lastName":"Doe",
        "phoneNumber":"0987654321",
        "email":"john@doe.com",
        "friend":
            {
                "firstName":"Jane",
                "lastName":"Doe",
            }
    },
    {
        "id":"2",
        "firstName":"Rye",
        "lastName":"Dale",
        "phoneNumber":"0123456789",
        "email":"rye@dale.com",
        "friend":
            {
                "firstName":"John",
                "lastName":"Dale",
            }
    }
]

this is the laravel eloquent to output to json.

$result = Group::with('friends')
->get(array('id', 'firstName', 'lastName', 'phoneNumber', 'email'));

return Response::json(array(
    'group' => $result->toArray()),
    200
);  

I had it sorted out. thanks for all your help. using httpful, you can parse with this.

foreach ($response->body->groups as $group)
{
    echo "id: ". $group->id;
    echo "firstName: ". $group->firstName;
    echo "lastName: ". $group->lastName;
    echo "phoneNumber: ". $leads->phoneNumber;
    echo "email: ". $group->email;
    echo "Friend's Name: ". $group->friend->firstName . $group->friend->lastName;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM