PHP API echo Array(Bigcommerce)

时间:2017-10-25 07:18:48

标签: php arrays api

' shipping_address'显示错误"注意:数组到字符串转换",我有这行代码:

编辑 - 删除了代码段并将其替换为连接到BigCommerce商店的完整代码

<?php
require 'vendor/autoload.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
    'store_url' => 'xxx',
    'username'  => 'xxx',
    'api_key'   => 'xxx'
));
$ping = Bigcommerce::getTime();


$orders = Bigcommerce::getOrders();
$data = json_decode($shipping_address, true);
foreach ($orders as $orders) {

     echo "<table border='1' width='100%' cellspacing='0' cellpadding='5' bordercolor='#000' style='border-bottom:0;'>
        <tr>
        <th width='15%'>Barcode</th>
        <th width='7%'>Order date</th>
        <th width='23%'>Customer details</th>
        <th width='8%'>Phone #</th>
        <th width='22%'>Total</th>
        <th width='15%'>Comments</th>
        <th width='10%'>Signature</th>
        </tr>";


    echo "<tr>";
    echo "<td style='text-align:center;'>" $orders->id . "</td>";
    echo "<td>" . $orders->date_created . "</td>";
    echo "<td>" . $shipping_address = $orders['shipping_address'][0]['first_name'] . "</td>";
     echo "<td>" . $orders->phone . "</td>";
    echo "<td style='text-align:center;'>" . $orders->total_inc_tax . "</td>";
    echo "<td>" . $orders->customer_message . "</td>";
     echo "<td>" . "</td>";
    echo "</tr>";
    echo "</table>";

}

?>

3 个答案:

答案 0 :(得分:0)

您不能直接显示数组,而是可以这样显示:

<td>
<?php foreach($orders->shipping_addresses as $address): ?>
"first_name": <?=$address['first_name']?>
"last_name": <?=$address['last_name']?>
"company": <?=$address['company']?>
"street_1": <?=$address['street_1']?>
"street_2": <?=$address['street_2']?>
"phone": <?=$address['phone']?>
"email": <?=$address['email']?>
<br />
<?php endforeach; ?> 
</td>

当然,您应该使用以下方法解码json:

 json_decode($json, true);

答案 1 :(得分:0)

您是否会为上述地址确定变量$address?例如:

$address = 'Street1:' . $orders->shipping_addresses['street_1'] . '<br>Street2' . $orders->shipping_addresses['street_2'];

此外,您可以使用此内联

echo "<td>" . $orders->shipping_addresses['street_1'] . "</td>";

如果$orders->shipping_addresses被解码为json。

json_decode($shipping_addresses, true); 

答案 2 :(得分:0)

如果这是您想要的列

GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2017-05-10

尝试

John Doe
Company
Street 1
Street 2
+1234567890
johndoe@example.com