Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

php获取到的数组中包含object,get_object_vars 和 json_decode取不出来 object中的值

php获取到的数组中包含object,

array(6) {
  ["dev_system"]=>
  string(3) "ios"
  ["json_expired"]=>
  string(15) "[object Object]"
  ["video_ext"]=>
  string(4) ".mp4"
  ["file_video"]=>
  string(107) "http://tmp/wx2cf493c28d639a7d.o6zAJs2-BlpW_m7zOglwJfmmJmpw.p9MALdMHhG1Q1c228b07b2f2bc699a6399b18dcbfd84.mp4"
  ["v_size_o"]=>
  string(7) "4616520"
  ["login_code"]=>
  string(32) "0018H9Ga10whVz0B6KHa1G0ZT318H9GQ"
}

可以看到 json_expired 是个 object,现在需要取出 json_expired中的值,试了 get_object_vars 和 json_decode取不出来 ,怎么破?

        echo "<pre>";
        $arr_post=json_decode(json_encode($arr_post),true);
        var_dump($arr_post);
        echo "</pre>";
array(6) {
  ["dev_system"]=>
  string(3) "ios"
  ["json_expired"]=>
  string(15) "[object Object]"
  ["video_ext"]=>
  string(4) ".mp4"
  ["file_video"]=>
  string(107) "http://tmp/wx2cf493c28d639a7d.o6zAJs2-BlpW_m7zOglwJfmmJmpw.p9MALdMHhG1Q1c228b07b2f2bc699a6399b18dcbfd84.mp4"
  ["v_size_o"]=>
  string(7) "4616520"
  ["login_code"]=>
  string(32) "0018H9Ga10whVz0B6KHa1G0ZT318H9GQ"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

是对象就按照对象的方式来处理啊..如果你知道他是啥对象的实例,就去操作其对象的属性和函数.如果你不知道他是啥对象的实例,可以用反射来获取他的属性和函数信息..

话说,你这应该是一个 api 的响应吧.文档里应该有描述这个值是个啥对象吧.如果提供了 sdk 的话,sdk 里就应该由这个对象啊.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...