I am working with ExtJs 4.0. I want to read json file in my chart but gettig following error
Ext.Error: Unable to parse the JSON returned by the server: You’re trying to decode an invalid JSON String.
store n model:
Ext.define('chartModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'year'},
{name: 'comedy'},
{name: 'action'},
{name: 'drama'},
{name: 'thriller'}
]
});
var myStore = Ext.create('Ext.data.Store', {
model: chartModel,
proxy: {
type: 'ajax',
url : '/data.json',
reader: {
type: 'json',
root: 'data',
method: "GET",
messageProperty: 'jsonData'
}
},
autoLoad: true
});
data.json file:
data: [{year: 2005, comedy: 34000000, action: 23890000, drama: 18450000, thriller: 20060000}]
JSON property names must be quoted to be considered valid. In addition, your
dataneeds to be a property of an object, like{"data":[{"year":2005, "comedy":3400000....EDIT: What Neil said is correct.
Ext.decodedoes not require property names to be in quotes. However, the JSON standard does require them so you should definitely get in the habit of using them.