dongzuo9096 2014-12-11 02:03
浏览 106
已采纳

从laravel eloquent解析json到http的http

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",
            }
    }
]
  • 写回答

2条回答 默认 最新

  • dongyu4863 2014-12-11 03:46
    关注

    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;
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?