PDA

View Full Version : Json parsing problem in sencha



ratheeshrohini
24 Feb 2012, 2:19 AM
Hi,
I have a .json file in the following format.Now I want to parse this json for drawing a chart



{
"version": 1,
"report_type": "dashboard",
"title": "Daily Sales Report",
"sub_title": "",
"run_datetime": "February 2, 2012 22:13:00",
"panels": [
{
"title": "Daily Order Volume",
"sub_title": "",
"panel_type": "cumulative_line_graph",
"x_axis": {
"label": "Hour",
"values": [
0,
1,
2,
3,
22,
23,
24
]
}
}
]
}




While looking at http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Json I undestood how to parse this json and take the values of label,values(marked blue),Using the following code.


Ext.regModel('User', {
idProperty: 'label',
fields: ['label','values']
});
var store = new Ext.data.Store({
model: 'User',
autoLoad: true,
proxy: {
type: 'ajax',
method: 'GET',
url: 'resources/dailyreport.json',
reader: {
type: 'json',
root : 'panels',
record: 'x_axis'
}
},
listeners: {
load: function(obj, records){

Ext.each(records, function(rec){
alert(rec.get('label'));
});
}
}
});


But the problem is I want version,report_type,title too .....(marked red in above json).this is not possible using above code.

What I should change in above code to get all values(version,panel_type,label etc)?This is very urgent .can anyone help me?

mitchellsimoens
24 Feb 2012, 11:18 AM
There is going to be no way to do that with your store setup and JSON setup.

ratheeshrohini
24 Feb 2012, 8:07 PM
then can u tell me how can i parse the above json