【问题标题】:Access nested Json response with Guzzle Laravel使用 Guzzle Laravel 访问嵌套的 Json 响应
【发布时间】:2020-02-07 15:12:09
【问题描述】:

我在 Laravel 中通过 Guzzle 发出请求并收到如下响应:

{
    "ErrorCode": 0,
    "ErrorDescription": "Success.",
    "Data": [
        {
            "brand_id": 1,
            "tenant_id": "tn001",
            "brand_name": "ABC",
            "brand_url": "url.com",
            "brand_avatar": "avatar.com",
            "brand_banner": "banner.com",
            "brand_about": "abc."
        }
    ]
}

如何访问品牌名称字段?

谢谢!

【问题讨论】:

    标签: json laravel guzzle


    【解决方案1】:
    $response = json_decode($guzzleResponse,true);
    
    echo $response['Data'][0]['brand_name'];
    

    你只需要解码 json 到一个数组并像往常一样解析它。 请注意Data 中的嵌套数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      • 2014-03-25
      • 2019-10-08
      • 1970-01-01
      相关资源
      最近更新 更多