调用短信接口,先var_dump()看数据类型是object需要json_decode(json_encode( $resp),true)转换成array

返回的数据.先看类型,如果是object类型

先json_encode,

再json_decode,加true

转换成数组



$resp = $c->execute($req);

var_dump($resp);

object(stdClass)#12 (2) {
["result"]=> object(stdClass)#13 (3) {

["err_code"]=> string(1) "0"
["model"]=> string(26) "xxx"
["success"]=> bool(true)
}

返回的数据.是object对象时.务必转换成array才能使用


$arr = json_decode(json_encode( $resp),true);

var_dump($arr);

array(2) {
["result"]=> array(3) { ["err_code"]=> string(1) "0"
["model"]=> string(26) "xxxx" ["success"]=> bool(true) }
}

原文地址:https://www.cnblogs.com/bj-tony/p/5478472.html