Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / output / Ext.data.reader.Json.js
1 Ext.data.JsonP.Ext_data_reader_Json({
2   "tagname": "class",
3   "name": "Ext.data.reader.Json",
4   "doc": "<p>The JSON Reader is used by a Proxy to read a server response that is sent back in JSON format. This usually\nhappens as a result of loading a Store - for example we might create something like this:</p>\n\n\n\n\n<pre><code>Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name', 'email']\n});\n\nvar store = new Ext.data.Store({\n    model: 'User',\n    proxy: {\n        type: 'ajax',\n        url : 'users.json',\n        reader: {\n            type: 'json'\n        }\n    }\n});\n</code></pre>\n\n\n\n\n<p>The example above creates a 'User' model. Models are explained in the <a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">Model</a> docs if you're\nnot already familiar with them.</p>\n\n\n\n\n<p>We created the simplest type of JSON Reader possible by simply telling our <a href=\"#/api/Ext.data.Store\" rel=\"Ext.data.Store\" class=\"docClass\">Store</a>'s \n<a href=\"#/api/Ext.data.proxy.Proxy\" rel=\"Ext.data.proxy.Proxy\" class=\"docClass\">Proxy</a> that we want a JSON Reader. The Store automatically passes the configured model to the\nStore, so it is as if we passed this instead:\n\n<pre><code>reader: {\n    type : 'json',\n    model: 'User'\n}\n</code></pre>\n\n<p>The reader we set up is ready to read data from our server - at the moment it will accept a response like this:</p>\n\n<pre><code>[\n    {\n        \"id\": 1,\n        \"name\": \"Ed Spencer\",\n        \"email\": \"ed@sencha.com\"\n    },\n    {\n        \"id\": 2,\n        \"name\": \"Abe Elias\",\n        \"email\": \"abe@sencha.com\"\n    }\n]\n</code></pre>\n\n<p><u>Reading other JSON formats</u></p>\n\n<p>If you already have your JSON format defined and it doesn't look quite like what we have above, you can usually\npass JsonReader a couple of configuration options to make it parse your format. For example, we can use the \n<a href=\"#/api/Ext.data.reader.Json-cfg-root\" rel=\"Ext.data.reader.Json-cfg-root\" class=\"docClass\">root</a> configuration to parse data that comes back like this:</p>\n\n<pre><code>{\n    \"users\": [\n       {\n           \"id\": 1,\n           \"name\": \"Ed Spencer\",\n           \"email\": \"ed@sencha.com\"\n       },\n       {\n           \"id\": 2,\n           \"name\": \"Abe Elias\",\n           \"email\": \"abe@sencha.com\"\n       }\n    ]\n}\n</code></pre>\n\n<p>To parse this we just pass in a <a href=\"#/api/Ext.data.reader.Json-cfg-root\" rel=\"Ext.data.reader.Json-cfg-root\" class=\"docClass\">root</a> configuration that matches the 'users' above:</p>\n\n<pre><code>reader: {\n    type: 'json',\n    root: 'users'\n}\n</code></pre>\n\n<p>Sometimes the JSON structure is even more complicated. Document databases like CouchDB often provide metadata\naround each record inside a nested structure like this:</p>\n\n<pre><code>{\n    \"total\": 122,\n    \"offset\": 0,\n    \"users\": [\n        {\n            \"id\": \"ed-spencer-1\",\n            \"value\": 1,\n            \"user\": {\n                \"id\": 1,\n                \"name\": \"Ed Spencer\",\n                \"email\": \"ed@sencha.com\"\n            }\n        }\n    ]\n}\n</code></pre>\n\n<p>In the case above the record data is nested an additional level inside the \"users\" array as each \"user\" item has\nadditional metadata surrounding it ('id' and 'value' in this case). To parse data out of each \"user\" item in the \nJSON above we need to specify the <a href=\"#/api/Ext.data.reader.Json-cfg-record\" rel=\"Ext.data.reader.Json-cfg-record\" class=\"docClass\">record</a> configuration like this:</p>\n\n<pre><code>reader: {\n    type  : 'json',\n    root  : 'users',\n    record: 'user'\n}\n</code></pre>\n\n<p><u>Response metadata</u></p>\n\n<p>The server can return additional data in its response, such as the <a href=\"#/api/Ext.data.reader.Json-cfg-totalProperty\" rel=\"Ext.data.reader.Json-cfg-totalProperty\" class=\"docClass\">total number of records</a> \nand the <a href=\"#/api/Ext.data.reader.Json-cfg-successProperty\" rel=\"Ext.data.reader.Json-cfg-successProperty\" class=\"docClass\">success status of the response</a>. These are typically included in the JSON response\nlike this:</p>\n\n<pre><code>{\n    \"total\": 100,\n    \"success\": true,\n    \"users\": [\n        {\n            \"id\": 1,\n            \"name\": \"Ed Spencer\",\n            \"email\": \"ed@sencha.com\"\n        }\n    ]\n}\n</code></pre>\n\n<p>If these properties are present in the JSON response they can be parsed out by the JsonReader and used by the\nStore that loaded it. We can set up the names of these properties by specifying a final pair of configuration \noptions:</p>\n\n<pre><code>reader: {\n    type : 'json',\n    root : 'users',\n    totalProperty  : 'total',\n    successProperty: 'success'\n}\n</code></pre>\n\n<p>These final options are not necessary to make the Reader work, but can be useful when the server needs to report\nan error or if it needs to indicate that there is a lot of data available of which only a subset is currently being\nreturned.</p>\n\n",
5   "extends": "Ext.data.reader.Reader",
6   "mixins": [
7
8   ],
9   "alternateClassNames": [
10     "Ext.data.JsonReader"
11   ],
12   "xtype": null,
13   "author": "Ed Spencer",
14   "docauthor": null,
15   "singleton": false,
16   "private": false,
17   "cfg": [
18     {
19       "tagname": "cfg",
20       "name": "idProperty",
21       "member": "Ext.data.reader.Reader",
22       "type": "String",
23       "doc": "<p>Name of the property within a row object\nthat contains a record identifier value.  Defaults to <tt>The id of the model</tt>.\nIf an idProperty is explicitly specified it will override that of the one specified\non the model</p>\n",
24       "private": false,
25       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
26       "linenr": 153,
27       "html_filename": "Reader.html",
28       "href": "Reader.html#Ext-data-reader-Reader-cfg-idProperty",
29       "shortDoc": "Name of the property within a row object\nthat contains a record identifier value.  Defaults to The id of the model.\nI..."
30     },
31     {
32       "tagname": "cfg",
33       "name": "implicitIncludes",
34       "member": "Ext.data.reader.Reader",
35       "type": "Boolean",
36       "doc": "<p>True to automatically parse models nested within other models in a response\nobject. See the <a href=\"#/api/Ext.data.reader.Reader\" rel=\"Ext.data.reader.Reader\" class=\"docClass\">Ext.data.reader.Reader</a> intro docs for full explanation. Defaults to true.</p>\n",
37       "private": false,
38       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
39       "linenr": 190,
40       "html_filename": "Reader.html",
41       "href": "Reader.html#Ext-data-reader-Reader-cfg-implicitIncludes",
42       "shortDoc": "True to automatically parse models nested within other models in a response\nobject. See the Ext.data.reader.Reader in..."
43     },
44     {
45       "tagname": "cfg",
46       "name": "messageProperty",
47       "member": "Ext.data.reader.Reader",
48       "type": "String",
49       "doc": "<p>The name of the property which contains a response message.\nThis property is optional.</p>\n",
50       "private": false,
51       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
52       "linenr": 185,
53       "html_filename": "Reader.html",
54       "href": "Reader.html#Ext-data-reader-Reader-cfg-messageProperty"
55     },
56     {
57       "tagname": "cfg",
58       "name": "record",
59       "member": "Ext.data.reader.Json",
60       "type": "String",
61       "doc": "<p>The optional location within the JSON response that the record data itself can be found at.\nSee the JsonReader intro docs for more details. This is not often needed and defaults to undefined.</p>\n",
62       "private": false,
63       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Json.js",
64       "linenr": 167,
65       "html_filename": "Json.html",
66       "href": "Json.html#Ext-data-reader-Json-cfg-record",
67       "shortDoc": "The optional location within the JSON response that the record data itself can be found at.\nSee the JsonReader intro ..."
68     },
69     {
70       "tagname": "cfg",
71       "name": "root",
72       "member": "Ext.data.reader.Reader",
73       "type": "String",
74       "doc": "<p><b>Required</b>.  The name of the property\nwhich contains the Array of row objects.  Defaults to <tt>undefined</tt>.\nAn exception will be thrown if the root property is undefined. The data\npacket value for this property should be an empty array to clear the data\nor show no data.</p>\n",
75       "private": false,
76       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
77       "linenr": 176,
78       "html_filename": "Reader.html",
79       "href": "Reader.html#Ext-data-reader-Reader-cfg-root",
80       "shortDoc": "Required.  The name of the property\nwhich contains the Array of row objects.  Defaults to undefined.\nAn exception wil..."
81     },
82     {
83       "tagname": "cfg",
84       "name": "successProperty",
85       "member": "Ext.data.reader.Reader",
86       "type": "String",
87       "doc": "<p>Name of the property from which to\nretrieve the success attribute. Defaults to <tt>success</tt>.  See\n<a href=\"#/api/Ext.data.proxy.Proxy\" rel=\"Ext.data.proxy.Proxy\" class=\"docClass\">Ext.data.proxy.Proxy</a>.<a href=\"#/api/Ext.data.proxy.Proxy--exception\" rel=\"Ext.data.proxy.Proxy--exception\" class=\"docClass\">exception</a>\nfor additional information.</p>\n",
88       "private": false,
89       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
90       "linenr": 168,
91       "html_filename": "Reader.html",
92       "href": "Reader.html#Ext-data-reader-Reader-cfg-successProperty",
93       "shortDoc": "Name of the property from which to\nretrieve the success attribute. Defaults to success.  See\nExt.data.proxy.Proxy.exc..."
94     },
95     {
96       "tagname": "cfg",
97       "name": "totalProperty",
98       "member": "Ext.data.reader.Reader",
99       "type": "String",
100       "doc": "<p>Name of the property from which to\nretrieve the total number of records in the dataset. This is only needed\nif the whole dataset is not passed in one go, but is being paged from\nthe remote server.  Defaults to <tt>total</tt>.</p>\n",
101       "private": false,
102       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
103       "linenr": 160,
104       "html_filename": "Reader.html",
105       "href": "Reader.html#Ext-data-reader-Reader-cfg-totalProperty",
106       "shortDoc": "Name of the property from which to\nretrieve the total number of records in the dataset. This is only needed\nif the wh..."
107     },
108     {
109       "tagname": "cfg",
110       "name": "useSimpleAccessors",
111       "member": "Ext.data.reader.Json",
112       "type": "Boolean",
113       "doc": "<p>True to ensure that field names/mappings are treated as literals when\nreading values. Defalts to <tt>false</tt>.\nFor example, by default, using the mapping \"foo.bar.baz\" will try and read a property foo from the root, then a property bar\nfrom foo, then a property baz from bar. Setting the simple accessors to true will read the property with the name\n\"foo.bar.baz\" direct from the root object.</p>\n",
114       "private": false,
115       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Json.js",
116       "linenr": 172,
117       "html_filename": "Json.html",
118       "href": "Json.html#Ext-data-reader-Json-cfg-useSimpleAccessors",
119       "shortDoc": "True to ensure that field names/mappings are treated as literals when\nreading values. Defalts to false.\nFor example, ..."
120     }
121   ],
122   "method": [
123     {
124       "tagname": "method",
125       "name": "Json",
126       "member": "Ext.data.reader.Reader",
127       "doc": "\n",
128       "params": [
129         {
130           "type": "Object",
131           "name": "config",
132           "doc": "<p>Optional config object</p>\n",
133           "optional": false
134         }
135       ],
136       "return": {
137         "type": "void",
138         "doc": "\n"
139       },
140       "private": false,
141       "static": false,
142       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
143       "linenr": 1,
144       "html_filename": "Reader.html",
145       "href": "Reader.html#Ext-data-reader-Reader-method-constructor",
146       "shortDoc": "\n"
147     },
148     {
149       "tagname": "method",
150       "name": "getResponseData",
151       "member": "Ext.data.reader.Reader",
152       "doc": "<p>Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemented by each subclass</p>\n",
153       "params": [
154         {
155           "type": "Object",
156           "name": "response",
157           "doc": "<p>The responce object</p>\n",
158           "optional": false
159         }
160       ],
161       "return": {
162         "type": "Object",
163         "doc": "<p>The useful data from the response</p>\n"
164       },
165       "private": false,
166       "static": false,
167       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
168       "linenr": 458,
169       "html_filename": "Reader.html",
170       "href": "Reader.html#Ext-data-reader-Reader-method-getResponseData",
171       "shortDoc": "Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemen..."
172     },
173     {
174       "tagname": "method",
175       "name": "read",
176       "member": "Ext.data.reader.Reader",
177       "doc": "<p>Reads the given response object. This method normalizes the different types of response object that may be passed\nto it, before handing off the reading of records to the <a href=\"#/api/Ext.data.reader.Json-method-readRecords\" rel=\"Ext.data.reader.Json-method-readRecords\" class=\"docClass\">readRecords</a> function.</p>\n",
178       "params": [
179         {
180           "type": "Object",
181           "name": "response",
182           "doc": "<p>The response object. This may be either an XMLHttpRequest object or a plain JS object</p>\n",
183           "optional": false
184         }
185       ],
186       "return": {
187         "type": "Ext.data.ResultSet",
188         "doc": "<p>The parsed ResultSet object</p>\n"
189       },
190       "private": false,
191       "static": false,
192       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
193       "linenr": 226,
194       "html_filename": "Reader.html",
195       "href": "Reader.html#Ext-data-reader-Reader-method-read",
196       "shortDoc": "Reads the given response object. This method normalizes the different types of response object that may be passed\nto ..."
197     },
198     {
199       "tagname": "method",
200       "name": "readRecords",
201       "member": "Ext.data.reader.Json",
202       "doc": "<p>Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to\nretrieve meta data from the response, and extractData to turn the JSON data into model instances.</p>\n",
203       "params": [
204         {
205           "type": "Object",
206           "name": "data",
207           "doc": "<p>The raw JSON data</p>\n",
208           "optional": false
209         }
210       ],
211       "return": {
212         "type": "Ext.data.ResultSet",
213         "doc": "<p>A ResultSet containing model instances and meta data about the results</p>\n"
214       },
215       "private": false,
216       "static": false,
217       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Json.js",
218       "linenr": 181,
219       "html_filename": "Json.html",
220       "href": "Json.html#Ext-data-reader-Json-method-readRecords",
221       "shortDoc": "Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to\nretrieve meta da..."
222     }
223   ],
224   "property": [
225     {
226       "tagname": "property",
227       "name": "jsonData",
228       "member": "Ext.data.reader.Json",
229       "type": "Mixed",
230       "doc": "<p>DEPRECATED - will be removed in <a href=\"#/api/Ext\" rel=\"Ext\" class=\"docClass\">Ext</a> JS 5.0. This is just a copy of this.rawData - use that instead</p>\n",
231       "private": false,
232       "static": false,
233       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Json.js",
234       "linenr": 193,
235       "html_filename": "Json.html",
236       "href": "Json.html#Ext-data-reader-Json-property-jsonData"
237     },
238     {
239       "tagname": "property",
240       "name": "rawData",
241       "member": "Ext.data.reader.Reader",
242       "type": "Mixed",
243       "doc": "<p>The raw data object that was last passed to readRecords. Stored for further processing if needed</p>\n",
244       "private": false,
245       "static": false,
246       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
247       "linenr": 266,
248       "html_filename": "Reader.html",
249       "href": "Reader.html#Ext-data-reader-Reader-property-rawData"
250     }
251   ],
252   "event": [
253
254   ],
255   "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Json.js",
256   "linenr": 1,
257   "html_filename": "Json.html",
258   "href": "Json.html#Ext-data-reader-Json",
259   "cssVar": [
260
261   ],
262   "cssMixin": [
263
264   ],
265   "component": false,
266   "superclasses": [
267     "Ext.data.reader.Reader"
268   ],
269   "subclasses": [
270     "Ext.data.reader.Array"
271   ],
272   "mixedInto": [
273
274   ],
275   "allMixins": [
276
277   ]
278 });