【发布时间】:2015-03-28 18:47:05
【问题描述】:
我正在运行从 xml 数组中获取订单详细信息的脚本。问题是每次脚本运行时我都会遇到 foreach() 错误。我认为这是标题中的 htmlentities 但不确定。你能帮忙吗?
$products='';
$xml=simplexml_load_string($response);
$temp_arr=array();
foreach($xml->ListOrderItemsResult->OrderItems->OrderItem as $product)
{
$temp_arr[]=array('item'=>(string)$product->Title,'quantity'=>(string)$product->QuantityOrdered,'order_item_code'=>(string)$product->OrderItemId,'sku'=>(string)$product->SellerSKU);
}
return $temp_arr;
}
数组是正确的我检查数组带来的所有数据没有空值。
我在同一行收到 2 个错误 - foreach($xml->ListOrderItemsResult->OrderItems->OrderItem as $product)
试图获取非对象的属性
为 foreach() 提供的参数无效
XML
<?xml version="1.0"?>
<ListOrderItemsResponse xmlns="https://mws.amazonservices.com/Orders/2011-01-01">
<ListOrderItemsResult>
<OrderItems>
<OrderItem>
<OrderItemId>32080774637267</OrderItemId>
<GiftWrapPrice>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapPrice>
<QuantityOrdered>1</QuantityOrdered>
<GiftWrapTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapTax>
<SellerSKU>KS-MQOX-EUQ5</SellerSKU>
<Title>SINGLE DOUBLE & KING SIZE FITTED SHEETS Pillow cases BESPOKE BEDDING (Grey, pillowcases Standard 19"x29")</Title>
<ShippingTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingTax>
<ShippingPrice>
<Amount>2.95</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingPrice>
<ItemTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemTax>
<ItemPrice>
<Amount>2.99</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemPrice>
<PromotionDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</PromotionDiscount>
<ConditionId>New</ConditionId>
<ASIN>B00AFB1XH8</ASIN>
<QuantityShipped>0</QuantityShipped>
<ConditionSubtypeId>New</ConditionSubtypeId>
<ConditionNote>Brand New</ConditionNote>
<ShippingDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingDiscount>
</OrderItem>
</OrderItems>
<AmazonOrderId>026-3622751-4319550</AmazonOrderId>
</ListOrderItemsResult>
<ResponseMetadata>
<RequestId>42f09535-70e7-4a28-8413-cc439c42c030</RequestId>
</ResponseMetadata>
</ListOrderItemsResponse>
【问题讨论】:
-
有人可以帮我吗?
-
如果您能提供实际的 XML,或者至少是其中的一部分,那就太好了。
-
已更新..请检查
标签: php arrays xml codeigniter foreach