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?
searchResult->{'@attributes'}->countand you're fine. The other solution is to usetrueas second parameter forjson_decode. You then access everything as an array.