繁体   English   中英

PhP 致命错误:当我将值添加到 json 时,无法将字符串偏移量用作数组

[英]PhP Fatal Error: Cannot use string offset as an array when i add values to a json

我有一个 JSon 数组,我想添加(而不是编辑)值,但是当我尝试添加它时,出现致命错误。

这是我的代码:

错误发生在第一个$ext_data['order']['lang_iso']=$lang->iso_code;

$ext_order = array(
                    "order" => $order,
                    "order_detail" => getList($order->id),
                    "order_messages" => Message::getMessagesByOrderId($order->id),
                    "customer" => $customer,
                    "address_delivery" => $address_delivery,
                    "address_invoice" => $address_invoice,
                    "iso_codes" => $iso_codes,
                );
        
        
$ext_data = json_encode($ext_order, JSON_PRETTY_PRINT | JSON_PARTIAL_OUTPUT_ON_ERROR);
        
$ext_data['order']['lang_iso']=$lang->iso_code;
$ext_data['order']['carrier_name']=$carrier->name;
$ext_data['order']['ccurrency_iso']=$currency->iso_code;
$ext_data['customer']['lang_iso']=$lang_customer->iso_code;
$ext_data['address_delivery']['country_iso']=Country::getIsoById($address_delivery->id_country);
$ext_data['address_delivery']['state_iso']=$state_delivery->iso_code;
$ext_data['address_invoice']['country_iso']=Country::getIsoById($address_invoice->id_country);
$ext_data['address_invoice']['state_iso']=$state_invoice->iso_code;
   $order = json_decode(json_encode($order), true);   

   $ext_order = array(
                        "order" => $order,
                        "order_detail" => getList($order->id),
                        "order_messages" => Message::getMessagesByOrderId($order->id),
                        "customer" => $customer,
                        "address_delivery" => $address_delivery,
                        "address_invoice" => $address_invoice,
                        "iso_codes" => $iso_codes,
                    );
    
            
    $ext_order['order']['lang_iso']=$lang->iso_code;
    $ext_order['order']['carrier_name']=$carrier->name;
    $ext_order['order']['ccurrency_iso']=$currency->iso_code;
    $ext_order['customer']['lang_iso']=$lang_customer->iso_code;
    $ext_order['address_delivery']['country_iso']=Country::getIsoById($address_delivery->id_country);
    $ext_order['address_delivery']['state_iso']=$state_delivery->iso_code;
    $ext_order['address_invoice']['country_iso']=Country::getIsoById($address_invoice->id_country);
    $ext_order['address_invoice']['state_iso']=$state_invoice->iso_code;
    
    $ext_data = json_encode($ext_order, JSON_PRETTY_PRINT | JSON_PARTIAL_OUTPUT_ON_ERROR); // changed the order.

暂无
暂无

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

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