热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

斯蒂芬大帝通过反射函数转化为数组可以处理这样的问题$refnewReflectionClass($response);$props$ref-getProperties();$ar

ec30df656989c784a8d6827d19c75aa5.png

斯蒂芬大帝

通过反射函数转化为数组可以处理这样的问题

$ref = new ReflectionClass($response);

$props = $ref->getProperties();

$arr = [];

foreach ($props as $prop) {

$prop->setAccessible(true);

$arr[$prop->getName()] = $prop->getValue($response);

$prop->setAccessible(false);

}

可以得到这样的数组,问题解决了

array(7) {

["content"] => string(1048) "HTTP/1.1 200 OK

Server: Tengine

Date: Mon, 25 Jun 2018 02:22:15 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: 271C3605-1937-4FF4-8D9B-D8E0F530875C

Cache-Control: no-store

X-Ca-Error-Message: OK

Vary: Accept-Encoding

ufe-result: A2

Pragma: no-cache

Via: 71aae546d43b[web,200]

Set-COOKIE: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529893335|1529893335;Path=/

X-Ca-Debug-Info: {"TotalLatency":105,"ServiceLatency":56}

{"code":601,"message":"数据不存在","data":null}"

["body"] => string(52) "{"code":601,"message":"数据不存在","data":null}"

["header"] => string(996) "HTTP/1.1 200 OK

Server: Tengine

Date: Mon, 25 Jun 2018 02:22:15 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: 271C3605-1937-4FF4-8D9B-D8E0F530875C

Cache-Control: no-store

X-Ca-Error-Message: OK

Vary: Accept-Encoding

ufe-result: A2

Pragma: no-cache

Via: 71aae546d43b[web,200]

Set-COOKIE: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529893335|1529893335;Path=/

X-Ca-Debug-Info: {"TotalLatency":105,"ServiceLatency":56}

"

["requestId"] => string(36) "271C3605-1937-4FF4-8D9B-D8E0F530875C"

["errorMessage"] => string(2) "OK"

["contentType"] => string(31) "application/json; charset=UTF-8"

["httpStatusCode"] => int(200)

}



推荐阅读
author-avatar
NethJ
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有