3

I'm using davidsadler's PHP ebay SDK to integrate ebay in my PHP application. Every response is in the form of this type of xml. I've echoed

 before this response to see it clearly.

    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] => 
                                                                                        )

                                                                                )

I tried converting this response to json using json_encode function of php and simplexml_load_file etc functions. But the converted data is always empty. Any help would be appreciated.

Update: Issue has been resolved in the new version of eBay PHP SDK which 0.1.3 He added a new method in BaseType which is toArray() which converts the response to an associated array. Thanks to davidsadler. Link to changelog https://github.com/davidtsadler/ebay-sdk/blob/master/CHANGELOG.md#013---2015-06-20

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Danish Jamil
  • 1,090
  • 11
  • 31
  • I believe that is a serialized object. Try using `deserialize();` – taxicala Jun 23 '15 at 20:06
  • You can't JSON this response. It would be invalid JSON anyways. None the less, this is showing classes, scopes, and arrays. Try deserializing it and see if you get anything else. – Twister1002 Jun 23 '15 at 20:08
  • I just got a reply back from davidsadler creator of ebay SDK. He has just added a new method to to convert the response to an array. Thanks for your help anyway. – Danish Jamil Jun 23 '15 at 20:11

1 Answers1

0

try this http://goessner.net/download/prj/jsonxml/

Be sure to read the accompanying article on the xml.com O'Reilly site http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html, which goes into details of the problems with these conversions, which I think you will find enlightening. The fact that O'Reilly is hosting the article should indicate that Stefan's solution has merit.