PDA

View Full Version : How to map 2-dimentional array based json response to grid/store



sachindev
17 Feb 2012, 2:35 AM
How can we parse this Json response into our store: We can see that the response is in 2-dimentional array form. Is there any way to map it to our traditional "name:value" pair format?
Actual response: 

"Rows": {
                "Row": [
                    {
                        "Column": [
                            {
                                "id": "dutystatus1",
                                "type": "string",
                                "value": "Driving"
                            },
                           {
                                "id": "position",
                                "type": "string",
                                "value": "CA"
                            },.........  
                        ]
                    }, {
                        "Column": [
                            {
                                "id": "dutystatus1",
                                "type": "string",
                                "value": "Off Duty"
                            },  ........
                        ]
                    }
Expected name:value pair format:

"Rows" : {
                "Row" : [           {
                                     "dutystatus1":"driving",
                                     "starttime1":"2012-01-19 14:30(15:10)",
                                      "duration1": "1h13",
                                        "position1": "AL, Culman 12 miles E",
                                      "drivername1":"Dougherty Florence",
                                     "codrivername1": "Pavan"
                                     
                                    },
                                    {
                                     "dutystatus1":"driving",
                                     "starttime1":"2012-01-19 14:30(15:10)",
                                      "duration1": "1h13",
                                     "position1": "AL, Culman 12 miles E",
                                      "drivername1":"Dougherty Florence",
                                     "codrivername1": "Pavan"
                                    
                                    } .............
                             
                                   
                           ]
            }

friend
17 Feb 2012, 4:43 AM
Your input JSON appears to have a consistent format, so it should be fairly easy to write a generic script which walks the array of Columns for each Row and builds a JSON record for your target store.

Just use Ext.data.Store.add(<json>) to add each row to the target store.



myStore.add({dutystatus1: 'driving', drivername1: 'Dougherty Florence'});


I'd probably use an Ext.Ajax.request() to retrieve the data, then do the store load manually. Or, you could let the store call the target URL, then capture the beforeload event and massage the data there.

sachindev
21 Feb 2012, 5:22 AM
I am not able to get responseText, It is blank.  Please have a look on below code and suggest what i am doing wrong?

 Ext.Ajax.request({            url: 'http://query.yahooapis.com/v1/public/yql',
            params:{
            q: 'select * from rss where url="http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.xml"'    
            },
            method:'GET',
            withCredentials : true,
            success : function(response, opts) {
                    console.log("response "+response.responseText);
                //obj = Ext.decode(response.responseText);
            
                console.log(response);
            },
            failure : function(response, opts) {
                console.log("response "+response.responseText);
            }})    
            ]
        });    

Is it only working for .json files in URL?