简体   繁体   English

“尝试获取非对象的属性'listaOrdenes'”错误返回json

[英]“Trying to get property 'listaOrdenes' of non-object” error returning json

I have the following problem when returning to JSON from a function in PHP, when trying to read some of the properties of JSON, the following error returns to me. 从PHP中的函数返回JSON时,遇到以下问题,尝试读取JSON的某些属性时,以下错误返回给我。

  public function ObtenerListadoOrdenes(){
    try {
        $existeNueva = false;
        //OBTENEMOS LA LISTA DE ORDENES.
        $orderList = json_decode(CallApiRest::CallAPI('GET', $this->url.'/orders/get/list', false, $this->token));

        foreach($orderList as $item){
            $orderlist = OrderList::find($item->orderNumber);

            if ($orderlist == null){
                $existeNueva = true;

                $orderlist = new OrderList;

                $orderlist->orderNumber = $item->orderNumber;
                $orderlist->date = date('Y-m-d H:i:s', strtotime($item->date));

                $orderlist->save();
            }
        }

        $tempArray = array('existeNueva'=>$existeNueva, 'listaOrdenes'=>$orderList);

        return $tempArray;
    } catch (Exception $e) {
        echo 'Excepción capturada: ',  $e->getMessage(), "\n";
    }
}

The error return in the next code. 错误在下一个代码中返回。 return $listado->listaOrdenes; 返回$ listado-> listaOrdenes;

public function index()
    {
        $laudusApi = new LaudusApiConnect;
        $listado = $laudusApi->ObtenerListadoOrdenes();

        return $listado->listaOrdenes;
    }

The Error is : Trying to get property 'listaOrdenes' of non-object 错误是:试图获取非对象的属性“ listaOrdenes”

The result of $laudusApi->ObtenerListadoOrdenes(); $laudusApi->ObtenerListadoOrdenes();的结果$laudusApi->ObtenerListadoOrdenes(); is an array. 是一个数组。 In PHP arrays should be accessed as such: $listado['listaOrdenes']; 在PHP中,数组应该这样访问: $listado['listaOrdenes'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM