0

Possible Duplicate:
PHP/JSON - stdClass Object

I have this JSON response:

{
    "findItemsIneBayStoresResponse": {
        "ack": "Success",
        "version": "1.12.0",
        "timestamp": "2012-11-09T17:14:20.543Z",
        "searchResult": {
            "@attributes": {
                "count": "1"
            },
            "item": {
                "itemId": "160884918999",
                "topRatedListing": "false"
            }
        },
        "paginationOutput": {
            "totalPages": "1",
            "totalEntries": "1",
            "pageNumber": "1",
            "entriesPerPage": "100"
        }
    }
}

I am trying to access the 'count' in '@attributes' with PHP. I thought if ($decoded->findItemsIneBayStoresResponse->searchResult->@attributes->count > 1) { would work, but I get the error:

Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /home/ancienta/public_html/category.php on line 40

What can I do?

7
  • 5
    That is commonly asked, use curly braces: searchResult->{'@attributes'}->count and you're fine. The other solution is to use true as second parameter for json_decode. You then access everything as an array. Commented Nov 9, 2012 at 17:48
  • Wow. Great, thanks! I tried EVERYTHING except those. Duh. Commented Nov 9, 2012 at 17:49
  • See my edited comment, there are two ways to solve that. Commented Nov 9, 2012 at 17:50
  • I see that.... didn't know I could do that either. That might come in handy one day. Thanks for that tip. Commented Nov 9, 2012 at 17:50
  • 2
    I fail to see how it's a duplicate of that question .. Commented Nov 9, 2012 at 17:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.