object json转化为数组getcontent

发布时间:2020-03-14作者:小灵龙点击:190


//调用api 程序,通知商户订单异常 20200314
    public function calltoMerchant(){
      
            return json(['result'=>2,'msg'=>$result['msg']]);

       
    }
 $ycback=$this->calltoMerchant();
 var_dump($ycback);exit();

打印效果如下:

object(think\response\Json)#404 (7) {
  ["options":protected]=> array(1) {
    ["json_encode_param"]=> int(256)
}
  ["contentType":protected]=> string(16) "application/json"
  ["data":protected]=> array(2) {
    ["result"]=> int(1)
    ["msg"]=> string(6) "成功"
  }
  ["charset":protected]=> string(5) "utf-8"
  ["code":protected]=> int(200)
  ["header":protected]=> array(1) {
     ["Content-Type"]=> string(31) "application/json; charset=utf-8"
  }
  ["content":protected]=> NULL
}
如果加上getcontent()函数,打印结果是这样的:

var_dump($ycback->getcontent()); {"result":1,"msg":"成功"}
然后使用json_decode($string,true)就可以获取数组了。

标签: