我正在使用davidsadler's PHP ebay SDK将ebay集成到我的php应用程序中。每一个响应都是这种类型的xml。我在回应之前回响过,想看清楚。
DTS\eBaySDK\Trading\Types\ItemArrayType Object( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [Item] => DTS\eBaySDK\Types\UnboundType Object ( [data:DTS\eBaySDK\Types\UnboundType:private] => Array ( [0] => DTS\eBaySDK\Trading\Types\ItemType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [BuyItNowPrice] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 100 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ItemID] => 110163537686 [ListingDetails] => DTS\eBaySDK\Trading\Types\ListingDetailsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [StartTime] => DateTime Object ( [date] => 2015-06-16 17:20:21.000000 [timezone_type] => 2 [timezone] => Z ) [ViewItemURL] => http://cgi.sandbox.ebay.com/Test-/110163537686 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ListingDuration] => GTC [ListingType] => FixedPriceItem [Quantity] => 100 [SellingStatus] => DTS\eBaySDK\Trading\Types\SellingStatusType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [CurrentPrice] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 100 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ShippingDetails] => DTS\eBaySDK\Trading\Types\ShippingDetailsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [ShippingServiceOptions] => DTS\eBaySDK\Types\UnboundType Object ( [data:DTS\eBaySDK\Types\UnboundType:private] => Array ( [0] => DTS\eBaySDK\Trading\Types\ShippingServiceOptionsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [ShippingServiceCost] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 2 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [position:DTS\eBaySDK\Types\UnboundType:private] => 0 [class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\ShippingDetailsType [property:DTS\eBaySDK\Types\UnboundType:private] => ShippingServiceOptions [expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\ShippingServiceOptionsType ) [ShippingType] => Flat ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [TimeLeft] => P22DT21H24M4S [Title] => Test [QuantityAvailable] => 100 [SKU] => ABC-001 [PictureDetails] => DTS\eBaySDK\Trading\Types\PictureDetailsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [GalleryURL] => http://thumbs.sandbox.ebaystatic.com/pict/1101635376866464.jpg ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [SellerProfiles] => DTS\eBaySDK\Trading\Types\SellerProfilesType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [1] => DTS\eBaySDK\Trading\Types\ItemType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [BuyItNowPrice] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 89 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ItemID] => 110163540851 [ListingDetails] => DTS\eBaySDK\Trading\Types\ListingDetailsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [StartTime] => DateTime Object ( [date] => 2015-06-16 20:33:27.000000 [timezone_type] => 2 [timezone] => Z ) [ViewItemURL] => http://cgi.sandbox.ebay.com/watch-/110163540851 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ListingDuration] => GTC [ListingType] => FixedPriceItem [Quantity] => 20 [SellingStatus] => DTS\eBaySDK\Trading\Types\SellingStatusType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [CurrentPrice] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 89 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) [ShippingDetails] => DTS\eBaySDK\Trading\Types\ShippingDetailsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [ShippingServiceOptions] => DTS\eBaySDK\Types\UnboundType Object ( [data:DTS\eBaySDK\Types\UnboundType:private] => Array ( [0] => DTS\eBaySDK\Trading\Types\ShippingServiceOptionsType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [ShippingServiceCost] => DTS\eBaySDK\Trading\Types\AmountType Object ( [values:DTS\eBaySDK\Types\BaseType:private] => Array ( [currencyID] => USD [value] => 2 ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) ) ) [attachment:DTS\eBaySDK\Types\BaseType:private] => Array ( [data] => [mimeType] => ) )
我尝试使用php的json_encode函数和simplexml_load_file等函数将此响应转换为json。但是转换后的数据总是空的。任何帮助都将不胜感激。
更新:
新版本的ebay php sdk 0.1.3解决了这个问题。
他在baseType中添加了一个新方法toArray(),该方法将响应转换为关联数组。多亏了戴维萨德勒。链接到变更日志
https://github.com/davidtsadler/ebay-sdk/blob/master/CHANGELOG.md#013---2015-06-20

最佳答案

试试这个http://goessner.net/download/prj/jsonxml/
请务必阅读xml.com o'reilly站点http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html上随附的文章,其中详细介绍了这些转换的问题,我认为您会发现这些问题很有启发性。O'Reilly主持这篇文章的事实应该表明Stefan的解决方案是有价值的。

07-28 00:41