我有API请求并得到以下回复
object(Borla\Chikka\Models\Response)[175]
protected 'attributes' =>
array (size=3)
'status' => int 200
'message' => string 'ACCEPTED' (length=8)
'attachments' =>
object(Borla\Chikka\Base\Model)[176]
protected 'attributes' =>
array (size=2)
...
当我var_dump它时,它来自变量$ response。 如何访问该数组中的消息和状态?
答案 0 :(得分:2)
嗨,你需要这样做
对象到数组的数组
$array = get_object_vars($object);
print_r($array);
OR
function objectToArray( $object )
{
if( !is_object( $object ) && !is_array( $object ) )
{
return $object;
}
if( is_object( $object ) )
{
$object = get_object_vars( $object );
}
return array_map( 'objectToArray', $object );
}
/*** convert the array to object ***/
$array = objectToArray($account );
答案 1 :(得分:1)
尝试将对象转换为数组
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
<div id="text">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
答案 2 :(得分:-1)
找到答案,$result->message
和$result->status
。