1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      0  

    Default Get data from complicated JSON

    Get data from complicated JSON


    How to get data (I need ID and Name) from this JSON:
    Code:
    {"d" : {
    "results": [
    {
    "__metadata": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')", "type": "Noname.Configuration.Account"
    }, "Id": "42ce8b78-167e-4ce0-b971-000ec687a4ac", "Name": "Neri karra(nerikarra.com.ua)", "Owner": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Owner"
    }
    }, "CreatedOn": "\/Date(1320916078046)\/", "CreatedBy": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/CreatedBy"
    }
    }, "ModifiedOn": "\/Date(1320916078046)\/", "ModifiedBy": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/ModifiedBy"
    }
    }, "ProcessListeners": 0, "Ownership": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Ownership"
    }
    }, "PrimaryContact": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/PrimaryContact"
    }
    }, "Parent": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Parent"
    }
    }, "Industry": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Industry"
    }
    }, "Code": "", "Type": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Type"
    }
    }, "Phone": "(044) 287-47-09", "AdditionalPhone": "", "Fax": "", "Web": "nerikarra@nerikarra.com.ua", "AddressType": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/AddressType"
    }
    }, "Address": "", "City": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/City"
    }
    }, "Region": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Region"
    }
    }, "Zip": "", "Country": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Country"
    }
    }, "AccountCategory": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/AccountCategory"
    }
    }, "EmployeesNumber": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/EmployeesNumber"
    }
    }, "AnnualRevenue": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/AnnualRevenue"
    }
    }, "Notes": "", "Logo": {
    "__deferred": {
    "uri": "http://localhost:2376/WebApp/0/ServiceModel/EntityDataService.svc/AccountCollection(guid'42ce8b78-167e-4ce0-b971-000ec687a4ac')/Logo"
    }
    }, "AlternativeName": ""
    }
    ]
    }
    }
    Now I try to do it so:
    Code:
    Ext.regModel('JSONData', {            fields: ['ID', 'Name']
            });
            var JSONStore = new Ext.data.Store({
                model: 'JSONData',
                proxy: {
                    type: 'ajax',
                    headers: {
                        'Accept': 'application/json',
                        'Authorization': 'Basic ' + Ext.util.base64.encode('TestUser:TestUserPass')
                    },
                    url: 'ServiceModel/EntityDataService.svc/AccountCollection',
                    reader: {
                        type: 'json',
                        root: 'd'
                    }
                },
                autoLoad: true
            });
    But I get nothing (of course), cause node 'd' has another subnode 'results'. And only it has useful data. How to parse it correctly using reader of store (or another variant)?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    First Ext.regModel is deprecated, you should use Ext.define instead.

    Second, root config has been renamed to rootProperty.

    Third, you should assign rootProperty to 'd.results'
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      0  

    Default


    Great! Thanks a lot. 'd.results' solved my problem.

Thread Participants: 1