【问题标题】:How to read a json_decode result and dump it?如何读取 json_decode 结果并将其转储?
【发布时间】:2019-05-06 08:33:31
【问题描述】:

我的 json 响应有点问题。

我将它转储到我的 php 代码中,结果就是我在此处附加的内容

如何转储 statusText

我已经尝试过解码,我也尝试过:

dump($myVar['statusText']);

或者类似的东西

(为了获得我发布的我的 json 的转储,我刚刚做了 dump($myVar);)

JsonResponse {#325
  #data: "{"code":"OK","status":"ok","data":{"UUID":"f239ae18-98af-4224-8b4f-7713c71a5576","order":{something here },"orderRows":[something else here}}"
  #callback: null
  #encodingOptions: 271
  +headers: ResponseHeaderBag {#326
    #computedCacheControl: array:2 [
      "no-cache" => true
      "private" => true
    ]
    #cookies: []
    #headerNames: array:4 [
      "content-type" => "Content-Type"
      "access-control-allow-origin" => "Access-Control-Allow-Origin"
      "cache-control" => "Cache-Control"
      "date" => "Date"
    ]
    #headers: array:4 [
      "content-type" => array:1 [
        0 => "application/json; charset=utf-8"
      ]
      "access-control-allow-origin" => array:1 [
        0 => "*"
      ]
      "cache-control" => array:1 [
        0 => "no-cache, private"
      ]
      "date" => array:1 [
        0 => "Mon, 06 May 2019 08:15:28 GMT"
      ]
    ]
    #cacheControl: []
  }
  #content: "{"code":"OK","status":"ok","data":{"UUID":"f239ae18-98af-4224-8b4f-7713c71a5576","order":{something},"orderRows":[something else}}"
  #version: "1.0"
  #statusCode: 200
  #statusText: "OK"
  #charset: null
}

只是想看看 "status" => 'ok' 我的生活会很完美 :D

【问题讨论】:

标签: php json jsonresponse


【解决方案1】:

看看这个输出,看起来代码也存储在内容中。

“状态”:“正常”

因此,按照getData() 方法上的this documentation,您应该能够检索到状态:

$data = $myVar->getData();
var_dump($data->status);

预计这将返回一个字符串“ok”。

【讨论】:

  • 我已经尝试过这种方式,但不用说,它没有成功。最后,我更仔细地阅读了 json_encode 和 json_decode 的 php 文档,我发现如果我以 2 par 的身份通过。 “真”,我的对象变成了一个数组。就这样 !顺便说一句,Ty 回答!
猜你喜欢
  • 2021-12-28
  • 1970-01-01
  • 2011-07-09
  • 2017-02-03
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多