1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    yesakmac is on a distinguished road

      0  

    Default Unanswered: JSON with parenthesis

    Unanswered: JSON with parenthesis


    I'm taking some JSON output and loading it into a store. The JSON String is
    Code:
    {"totalCount":"3","Events":[{"EVENTNUM":"T00000000133","SUM(A.NUM_CUST)":61.0,"SUM(A.OUT_MINUTES)":13.0,"XPERS":796072.0,"OFF_DTS":"20130307084811CS","MAX(A.RESTORE_DTS)":"20130307090200CS","CAUSE":"10","FEEDER":"17FL012011","DEV_NAME":"T007F12127","WEATHER_CODE":"THUNDERSTORM","COMPLETION_REMARKS":"Testing Step Restore for Kasey"},{"EVENTNUM":"T00000000014","SUM(A.NUM_CUST)":61.0,"SUM(A.OUT_MINUTES)":4.0,"XPERS":796072.0,"OFF_DTS":"20130304135945CS","MAX(A.RESTORE_DTS)":"20130304140400CS","CAUSE":"09","FEEDER":"17FL012011","DEV_NAME":"T007F12127","WEATHER_CODE":"NORMAL FOR SEASON","COMPLETION_REMARKS":"COMPLETETION REMARKS FROM TRUCK ON TOFS. "},{"EVENTNUM":"T00000000173","SUM(A.NUM_CUST)":61.0,"SUM(A.OUT_MINUTES)":3.0,"XPERS":79607.0,"OFF_DTS":"20130307161424CS","MAX(A.RESTORE_DTS)":"20130307161800CS","CAUSE":"01","FEEDER":"17FL012011","DEV_NAME":"T007F12127","WEATHER_CODE":"LIGNTNING IN AREA","COMPLETION_REMARKS":"wetr"}]}
    which is valid JSON. The issue is I can't seem to get the "SUM(A.NUM_CUST), SUM(A.OUT_MINUTES), and MAX(A.RESTORE_DTS) to load into my model. I think it may be an issue with the parenthesis in the JSON.

    The JSON is valid, here's my model and store info:


    Code:
    //DEFINE MODEL Ext.define('User', {
         extend: 'Ext.data.Model',
         fields: [
                { name: 'ID' },
                { name: 'XFMR' },
                { name: 'XPERS' },
                { name: 'EVENTNUM' },
                { name: 'SUM(A.NUM_CUST)' },
                { name: 'SUM(A.OUT_MINUTES)' },
                { name: 'MAX(A.RESTORE_DTS)', type: 'date', dateFormat: 'YmdHisT' },
                { name: 'OFF_DTS', type: 'date', dateFormat: 'YmdHisT' },
                { name: 'WE_PREMISE' },
                { name: 'WEATHER_CODE' },
                { name: 'COMPLETION_REMARKS' },
                { name: 'CAUSE' },
                { name: 'FEEDER' },
                { name: 'DEV_NAME' }
                
                ]
            });
     //GET DATA
     var myStore = Ext.create('Ext.data.Store', {
         model: 'User',
         proxy: {
             type: 'ajax',
             url:'/omsportal/Application/Framework/getListByDevice.aspx?device=' + device,
                reader:
                    {
                     root: 'Events',
                     totalProperty: 'totalCount'
                    }
                   },    
            autoLoad: true
        });    
        //LOAD DATA
        myStore.load();
        // DRAW GRID
        var grid = new Ext.grid.GridPanel({
            store: myStore,
            columns: [
                //{ID: 'ID', header: 'ID', width: 50, sortable:true, dataIndex: 'ID'},
                 { header: 'OUTAGE DEVICE', width: 100, sortable: true, dataIndex: 'DEV_NAME', renderer: deviceRenderer },
                { header: 'OFFTIME', width: 150, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y H:i:s'), dataIndex: 'OFF_DTS' },
                { header: 'RESTORE TIME', width: 150, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y H:i:s'), dataIndex: 'MAX(A.RESTORE_DTS)' },
                { header: 'CAUSE CODE', width: 150, sortable: true, dataIndex: 'CAUSE', renderer: causeDecode },
                { header: 'WEATHER CODE', width: 90, sortable: true, dataIndex: 'WEATHER_CODE' },
                { header: 'COMPLETION REMARKS', width: 200, sortable: true, dataIndex: 'COMPLETION_REMARKS' },
                { header: 'MINUTES', width: 60, sortable: true, dataIndex: 'SUM(A.OUT_MINUTES)' },
                { header: 'CUSTOMERS', width: 80, sortable: true, dataIndex: 'SUM(A.NUM_CUST)' },
                { header: 'CLOSED BY', width: 90, sortable: true, dataIndex: 'XPERS' },
                { header: 'EVENT NUMBER', width: 90, sortable: true, dataIndex: 'EVENTNUM', renderer: eventRenderer }
            ],
            renderTo:'DeviceGrid'
           
    
    
    
    
    
        });


    Any help is appreciated. Thanks!

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,789
    Answers
    451
    Vote Rating
    597
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    In this case you should probably give your field names something more simple and use a mapping to get the data:

    Code:
    Ext.define('User', {
        extend : 'Ext.data.Model',
        fields : [{
            name : 'ID'
        }, {
            name : 'XFMR'
        }, {
            name : 'XPERS'
        }, {
            name : 'EVENTNUM'
        }, {
            name : 'foo',
            mapping : 'SUM(A.NUM_CUST)'
        }, {
            name : 'bar',
            mapping : 'SUM(A.OUT_MINUTES)'
        }, {
            name : 'baz',
            mapping : 'MAX(A.RESTORE_DTS)',
            type : 'date',
            dateFormat : 'YmdHisT'
        }, {
            name : 'OFF_DTS',
            type : 'date',
            dateFormat : 'YmdHisT'
        }, {
            name : 'WE_PREMISE'
        }, {
            name : 'WEATHER_CODE'
        }, {
            name : 'COMPLETION_REMARKS'
        }, {
            name : 'CAUSE'
        }, {
            name : 'FEEDER'
        }, {
            name : 'DEV_NAME'
        }]
    });
    
    Ext.onReady(function() {
        var data = {
            "totalCount" : "3",
            "Events" : [{
                "EVENTNUM" : "T00000000133",
                "SUM(A.NUM_CUST)" : 61.0,
                "SUM(A.OUT_MINUTES)" : 13.0,
                "XPERS" : 796072.0,
                "OFF_DTS" : "20130307084811CS",
                "MAX(A.RESTORE_DTS)" : "20130307090200CS",
                "CAUSE" : "10",
                "FEEDER" : "17FL012011",
                "DEV_NAME" : "T007F12127",
                "WEATHER_CODE" : "THUNDERSTORM",
                "COMPLETION_REMARKS" : "Testing Step Restore for Kasey"
            }, {
                "EVENTNUM" : "T00000000014",
                "SUM(A.NUM_CUST)" : 61.0,
                "SUM(A.OUT_MINUTES)" : 4.0,
                "XPERS" : 796072.0,
                "OFF_DTS" : "20130304135945CS",
                "MAX(A.RESTORE_DTS)" : "20130304140400CS",
                "CAUSE" : "09",
                "FEEDER" : "17FL012011",
                "DEV_NAME" : "T007F12127",
                "WEATHER_CODE" : "NORMAL FOR SEASON",
                "COMPLETION_REMARKS" : "COMPLETETION REMARKS FROM TRUCK ON TOFS. "
            }, {
                "EVENTNUM" : "T00000000173",
                "SUM(A.NUM_CUST)" : 61.0,
                "SUM(A.OUT_MINUTES)" : 3.0,
                "XPERS" : 79607.0,
                "OFF_DTS" : "20130307161424CS",
                "MAX(A.RESTORE_DTS)" : "20130307161800CS",
                "CAUSE" : "01",
                "FEEDER" : "17FL012011",
                "DEV_NAME" : "T007F12127",
                "WEATHER_CODE" : "LIGNTNING IN AREA",
                "COMPLETION_REMARKS" : "wetr"
            }]
        };
    
        var myStore = Ext.create('Ext.data.Store', {
            model : 'User',
            proxy : {
                type : 'memory',
                reader : {
                    useSimpleAccessors: true,
                    type: 'json',
                    root : 'Events',
                    totalProperty : 'totalCount'
                }
            }
        });
        
        myStore.loadRawData(data);
        console.log(myStore.first().get('foo'));
    
    });
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    yesakmac is on a distinguished road

      0  

    Default


    Still isn't populating the store with the information, even after I modified the fields

    Code:
    { name: 'ID' },			{ name: 'XFMR' },
                { name: 'XPERS' },
                { name: 'EVENTNUM' },
                {
                    name:    'NUM_CUST',
                    mapping: 'SUM(A.NUM_CUST)'},
                {
                    name:    'OUT_MINUTES',
                    mapping: 'SUM(A.OUT_MINUTES)'},
                {
                    name:    'RESTORE_DTS',
                    mapping: 'MAX(A.RESTORE_DTS)', type: 'date', dateFormat: 'YmdHisT'
                },
                { name: 'OFF_DTS', type: 'date', dateFormat: 'YmdHisT' },
                { name: 'WE_PREMISE' },
    			{ name: 'WEATHER_CODE' },
    			{ name: 'COMPLETION_REMARKS' },
    			{ name: 'CAUSE' },
    			{ name: 'FEEDER' },
                { name: 'DEV_NAME' }
    This advice is great, anything else you can think to look at?

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,789
    Answers
    451
    Vote Rating
    597
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    I ran your code against the 4.2 beta, and it extracted the data as expected.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,572
    Answers
    540
    Vote Rating
    307
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    The key line in evant's code:

    Code:
    useSimpleAccessors: true
    Blink and you'd miss it...

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."