skip to Main Content

I am trying to decode a JSON response that I am receiving from the ebay finding API. How can I get it to echo out the ack message?

Here is the json response:

{
   "findItemsByCategoryResponse":[
      {
         "ack":[
            "Success"
         ],
         "version":[
            "1.12.0"
         ],
         "timestamp":[
            "2013-08-23T10:12:22.085Z"
         ],
         "searchResult":[
            {
               "@count":"1",
               "item":[
                  {
                     "itemId":[
                        "121158900630"
                     ],
                     "title":[
                        "SHAMROCK SHORES, TX - MONTHLY PAYMENTS - 0 INTEREST"
                     ],
                     "globalId":[
                        "EBAY-US"
                     ],
                     "subtitle":[
                        "blocks from Lake Brownwood"
                     ],
                     "primaryCategory":[
                        {
                           "categoryId":[
                              "15841"
                           ],
                           "categoryName":[
                              "Land"
                           ]
                        }
                     ],
                     "galleryURL":[
                        "http://thumbs3.ebaystatic.com/m/mP-wKIofn8JI9YsMduq6eUw/140.jpg"
                     ],
                     "viewItemURL":[
                        "http://www.ebay.com/itm/SHAMROCK-SHORES-TX-MONTHLY-PAYMENTS-0-INTEREST-/121158900630?pt=Land"
                     ],
                     "autoPay":[
                        "false"
                     ],
                     "postalCode":[
                        "76801"
                     ],
                     "location":[
                        "Brownwood,TX,USA"
                     ],
                     "country":[
                        "US"
                     ],
                     "shippingInfo":[
                        {
                           "shippingType":[
                              "FreePickup"
                           ],
                           "shipToLocations":[
                              "None"
                           ],
                           "expeditedShipping":[
                              "false"
                           ],
                           "oneDayShippingAvailable":[
                              "false"
                           ]
                        }
                     ],
                     "sellingStatus":[
                        {
                           "currentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"26.0"
                              }
                           ],
                           "convertedCurrentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"26.0"
                              }
                           ],
                           "bidCount":[
                              "4"
                           ],
                           "sellingState":[
                              "Active"
                           ],
                           "timeLeft":[
                              "P0DT1H12M13S"
                           ]
                        }
                     ],
                     "listingInfo":[
                        {
                           "bestOfferEnabled":[
                              "false"
                           ],
                           "buyItNowAvailable":[
                              "false"
                           ],
                           "startTime":[
                              "2013-08-13T11:24:35.000Z"
                           ],
                           "endTime":[
                              "2013-08-23T11:24:35.000Z"
                           ],
                           "listingType":[
                              "Auction"
                           ],
                           "gift":[
                              "false"
                           ]
                        }
                     ],
                     "returnsAccepted":[
                        "false"
                     ],
                     "isMultiVariationListing":[
                        "false"
                     ],
                     "topRatedListing":[
                        "false"
                     ]
                  }
               ]
            }
         ],
         "paginationOutput":[
            {
               "pageNumber":[
                  "1"
               ],
               "entriesPerPage":[
                  "1"
               ],
               "totalPages":[
                  "631"
               ],
               "totalEntries":[
                  "631"
               ]
            }
         ],
         "itemSearchURL":[
            "http://www.ebay.com/sch/15841/i.html?_ddo=1&_ipg=1&_pgn=1"
         ]
      }
   ]
}

The following is my php code:

$url = "http://svcs.ebay.com/services/search/FindingService/v1?" . 
        "OPERATION-NAME=findItemsByCategory&" . 
        "SERVICE-VERSION=1.0.0&" .
        "SECURITY-APPNAME=YourKeyHere&" . 
        "RESPONSE-DATA-FORMAT=JSON&" . 
        "REST-PAYLOAD&" . 
        "categoryId=15841&" . 
        "paginationInput.entriesPerPage=1";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
curl_close($ch);     

$json = json_decode($output, true);

$status = $json['findItemsByCategory']['ack'];
echo $status;

2

Answers


  1. findItemsByCategoryResponse is an array, the first element of which has ack:

    $status = $json['findItemsByCategoryResponse'][0]['ack'];
    // -------------------------------------------^^^
    

    Oddly, ack is also an array, so to get the text "Success" you’d have to dereference that, too:

    $status = $json['findItemsByCategoryResponse'][0]['ack'][0];
    // -------------------------------------------^^^-------^^^
    
    Login or Signup to reply.
  2. Assuming $json contains the receied json response, You can use the below:

    $obj = json_decode($json);
    $status = $obj->findItemsByCategoryResponse[0]->ack;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search