为了账号安全,请及时绑定邮箱和手机立即绑定

php如何处理一个对象,并且获取对象元素的值,下面有object?

php如何处理一个对象,并且获取对象元素的值,下面有object?

PHP
慕桂英3389331 2019-03-12 00:49:19
我想获取body的值,怎么做 object(HttpResponse)#11 (7) { ["content":"HttpResponse":private] => string(1047) "HTTP/1.1 200 OK Server: Tengine Date: Fri, 22 Jun 2018 09:52:33 GMT Content-Type: application/json; charset=UTF-8 Content-Length: 52 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5 Access-Control-Max-Age: 172800 X-Ca-Request-Id: CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE Vary: Accept-Encoding ufe-result: A2 Pragma: no-cache Cache-Control: no-store Via: 71aae546d43b[web,200] Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529661153|1529661153;Path=/ X-Ca-Error-Message: OK X-Ca-Debug-Info: {"TotalLatency":81,"ServiceLatency":55} {"code":601,"message":"数据不存在","data":null}" ["body":"HttpResponse":private] => string(52) "{"code":601,"message":"数据不存在","data":null}" ["header":"HttpResponse":private] => string(995) "HTTP/1.1 200 OK Server: Tengine Date: Fri, 22 Jun 2018 09:52:33 GMT Content-Type: application/json; charset=UTF-8 Content-Length: 52 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5 Access-Control-Max-Age: 172800 X-Ca-Request-Id: CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE Vary: Accept-Encoding ufe-result: A2 Pragma: no-cache Cache-Control: no-store Via: 71aae546d43b[web,200] Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529661153|1529661153;Path=/ X-Ca-Error-Message: OK X-Ca-Debug-Info: {"TotalLatency":81,"ServiceLatency":55} " ["requestId":"HttpResponse":private] => string(36) "CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE" ["errorMessage":"HttpResponse":private] => string(2) "OK" ["contentType":"HttpResponse":private] => string(31) "application/json; charset=UTF-8" ["httpStatusCode":"HttpResponse":private] => int(200) }
查看完整描述

6 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

get_object_vars 可以把对象转换为数组

查看完整回答
反对 回复 2019-03-18
?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

把对象转成数组看看

查看完整回答
反对 回复 2019-03-18
?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

$object->body试下

查看完整回答
反对 回复 2019-03-18
?
当年话下

TA贡献1890条经验 获得超9个赞

谢邀.

不管对象里面有没有子对象,你可以采用下面的方法搞定

//将对象序列化,然后转换为数组
$arr=json_decode(json_encode($obj),true);

通过数组方式你很容易访问对象中的元素。

参考 php对象转数组的黑技术
查看完整回答
反对 回复 2019-03-18
  • 6 回答
  • 0 关注
  • 6866 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信