Laravel 在 blade 中获取包含 'bns:OrderId' 名称的数组?

Laravel get array in blade with such 'bns:OrderId' names in it?

我从外部公司获得一个数组来处理我的 laravel 应用程序

传入的 json 中有类似 'bns:OrderId' 的名称?

blade 当我尝试访问 {{ $order->bns:OrderId }}

时出现错误

我该如何处理?

控制器:

    public function getBolOrders()
{
    // or live API: https://plazaapi.bol.com
    $url = 'https://test-plazaapi.bol.com';
    $uri = '/services/rest/orders/v1/open';

    // your public key
    $public_key = '<public key>';

    //your private key
    $private_key = '<private key>';

    $port = 443;
    $contenttype = 'application/xml';
    $date = gmdate('D, d M Y H:i:s T');
    $httpmethod = 'GET';

    $signature_string = $httpmethod . "\n\n";
    $signature_string .= $contenttype . "\n";
    $signature_string .= $date."\n";
    $signature_string .= "x-bol-date:" . $date . "\n";
    $signature_string .= $uri;
    $signature = $public_key.':'.base64_encode(hash_hmac('SHA256', $signature_string, $private_key, true));

    // Setup CURL (One can also opt to use sockets or http libraries, but CURL is a versatile, widespread solution)
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: ".$contenttype, "X-BOL-Date:".$date, "X-BOL-Authorization: ".$signature));
    curl_setopt($ch, CURLOPT_URL, $url.$uri);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_PORT, $port);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    $result = curl_exec($ch);
    $orders = fopen("orders.xml", "w");
    fwrite($orders, $result);
    fclose($orders);
    if(curl_errno($ch)) {
       print_r(curl_errno($ch), true);
    }
// Clean up after ourselves
    curl_close($ch);
// Convert XML TO JSON
    $xmlNode = simplexml_load_file('orders.xml');
    $arrayData = xmlToArray($xmlNode);
    $OpenOrder = $arrayData['OpenOrders']['bns:OpenOrder'];
//    dd($OpenOrder);
// Goto view
    return view('bol.open-orders', compact('OpenOrder'));
}

从数组添加:

array:2 [▼
  0 => array:6 [▼
   "bns:OrderId" => "123"
   "bns:DateTimeCustomer" => "2016-11-07T15:20:08.904"
   "bns:DateTimeDropShipper" => "2016-11-07T15:20:08.904"
   "bns:Paid" => "true"
   "bns:Buyer" => array:2 [▶]
   "bns:OpenOrderItems" => array:1 [▶]
 ]
 1 => array:6 [▼
   "bns:OrderId" => "321"
   "bns:DateTimeCustomer" => "2016-11-07T15:20:08.904"
   "bns:DateTimeDropShipper" => "2016-11-07T15:20:08.904"
   "bns:Paid" => "false"
   "bns:Buyer" => array:2 [▶]
   "bns:OpenOrderItems" => array:1 [▶]
   ]
]

示例 blade 模板:

@foreach ($OpenOrder as $order)
    {{ $order->bns:OrderId }}
@endforeach

此查询 returns arrays 值的集合不是 Object。使用此 {{ $order["bns:OrderId"] }} 而不是此 {{ $order->bns:OrderId }}.

试试这个:

@foreach ($OpenOrder as $order)
    {{ $order["bns:OrderId"] }}
@endforeach