Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Syntax, what is this?

Tags:

json

I understand concepts of JSON ok, but after starting to use ebay's api, I came across a notation which I've not seen before, and was wondering if anyone could explain what's going on with it?

{
    "findItemsByKeywordsResponse": [
        {
            "ack": [
                "Success" 
            ],
            "version": [
                "1.5.0" 
            ],
            "timestamp": [
                "2010-06-16T08:42:21.468Z" 
            ],
            "searchResult": [
                {
                    "@count": "0" 
                } 
            ],
            "paginationOutput": [
                {
                    "pageNumber": [
                        "0" 
                    ],
                    "entriesPerPage": [
                        "10" 
                    ],
                    "totalPages": [
                        "0" 
                    ],
                    "totalEntries": [
                        "0" 
                    ] 
                } 
            ] 
        } 
    ]
}

What's the "@count" thing? I noticed when I reference it in Chrome, it throws an error:

chrome error http://www.oth4.com/clip.jpg

But in Firefox not. JSON Lint reports it's valid, as I'd expect.

like image 722
dmp Avatar asked May 18 '26 08:05

dmp


2 Answers

It is a property name that starts with an @ character. That is all.

Use square bracket notation to access properties containing characters that you can't use in dot notation.

i.e.

currentPrice[0]['@currencyId']
like image 113
Quentin Avatar answered May 19 '26 21:05

Quentin


In addition to the answers here, @ usually appears in JSON property names when the JSON is created from XML. The @ represents an XML attribute so that it can be distinguished from the child elements of that XML node in it's new JSON form. For instance, that particular item in XML might look like this:

    <searchResult count="0">
    </searchResult>

As already suggested, you can access the property using square bracket notation.

like image 41
Andy E Avatar answered May 19 '26 23:05

Andy E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!