- Previous: Result Codes
- Up: Introduction
- Next: Code Samples
Response Format
RESPONSE PAYLOAD
The contents of the XML and JSON / JSONP are largely identical (one-to-one correlation) with only a few notable exceptions. The first exception is the response payload.
The XML response contains both the XML document header and the XML document root element named "response". The JSON response does not contain either of these components.
ARRAYS / LISTS
In order to make the concept of arrays work for both XML and JSON, we have introduced the concept of a "list" element in XML. All XML elements that represent an array contain the attribute "list" with a value of "true". They also contain the "size" attribute which is set, not surprisingly, to the number of elements in the list. This list element is largely implicit in the JSON response. (See examples below.)
Why do we do this? Developers using XML can quickly identify arrays in structured content. And developers using JSON can conveniently reference arrays as expected. That is, instead of having to type "activeDecades.decade[0]" or "activeDecades.decade.length" -- creating double references for all arrays -- a JSON developer can use"activeDecades[0]" or "activeDecades.length".
SIMPLE TYPES
XML types (integers, strings, boolean, etc.) for attribute / element values are specified in the various schemas, and implied somewhat in the attribute / element names. JSON variables are mapped to the appropriate JavaScript type. That is, integers are integers, strings are strings, etc.
EXAMPLES
Here is the same method response using each of the three formats. First, XML:
<?xml version="1.0" encoding="UTF-8"?>
<response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<status code="200">ok</status>
<options format="xml"/>
<artist group="false" id="10559083" name="Bob Marley"
published="true" url="http://www.emusic.com/artist/Bob-Marley-MP3-Download/10559083.html">
<origin location="St. Ann, Jamaica"/>
<death location="Miami, FL"/>
<activeDecades list="true" size="3">
<decade>1960</decade>
<decade>1970</decade>
<decade>1980</decade>
</activeDecades>
</artist>
</response>
{
"status": {
"code": 200,
"name": "ok"
}
"options": {"format": "json"},
"artist": {
"id": 10559083,
"name": "Bob Marley",
"url": "http://www.emusic.com/artist/Bob-Marley-MP3-Download/10559083.html"
"published": true,
"group": false,
"origin": {"location": "St. Ann, Jamaica"},
"death": {"location": "Miami, FL"},
"activeDecades": [
1960,
1970,
1980
],
},
}
someMethod({
"status": {
"code": 200,
"name": "ok"
}
"options": {"format": "json"},
"artist": {
...(same as JSON)...
},
});
- Previous: Result Codes
- Up: Introduction
- Next: Code Samples
Docs Navigation
- Introduction
- Request Format
- Response Elements
- Result Codes
- Response Format
- Code Samples
- Branding Guidelines
- Method Index
- Request Parameters
- Method: Album Charts
- Method: Album Editorial
- Method: Album Info
- Method: Album Picks
- Method: Album Ratings
- Method: Album Reviews
- Method: Album Search
- Method: Artist Charts
- Method: Artist Editorial
- Method: Artist Info
- Method: Artist Picks
- Method: Artist Ratings
- Method: Artist Related
- Method: Artist Search
- Method: Book Charts
- Method: Book Editorial
- Method: Book Info
- Method: Book Ratings
- Method: Book Reviews
- Method: Book Search
- Method: Label Info
- Method: Label Search
- Method: Track Charts
- Method: Track Search
0 Comments
Please sign in to post a comment.