Results 1 to 6 of 6

Thread: converting a JSON field into a variable

  1. #1
    Sencha User
    Join Date
    Sep 2010

    Default converting a JSON field into a variable

    I'm new to EXTJS, so please don't flame what I think is probably a very simple question.

    I'm trying to convert a field in a JSON array into a variable. What I'm trying to do in the code below is query the DB and extract the firstname from the array to display on the toolbar (although I've just made it a messagebox for now). The gameplan is use the variable outside the scope of the JSONSTORE so it can be used without overnesting the "SUCCESS".

    Any help much appreciated

    //create application = function() {
        return {
            init : function() {
    var priv = new{ 
        ,storeId: 'privdata'
    var jsonData = Ext.util.JSON.decode(priv);
    var sss =[0].firstname;
    this is the returned array from the php call
    {success: true, data: [{"firstname":"Charles","lastname":"Smith","home":"1","transport":"1","maintenance":"1","address_book":"0","event_planner":"0","admin":"0"}]}

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007


    autoLoad: {
        callback: fnWhichProcessesStore'sData
    And the Store is an object, not a JSON String. It's a.... well, it's a Store! Containing Records. Which are made up of Fields.

    What do you want to DO with these records in that callback?

  3. #3
    Sencha User
    Join Date
    Sep 2010


    Thanks for that Animal - I told you it was an easy one :-)

    What I'm aiming at doing is using the fields in the 1 record store to determine what menu buttons and access levels each logged in user is allowed to see/use. So in the example:

    firstname -> printed on the top toolbar (e.g. Welcome: Charles)
    home/maintenance/address_book etc. fields -> a 0 indicates that the menu button is hidden, a 1 indicates that the button is shown and the details for the 'button-function' are read only and a 2 has full edit access.

  4. #4


    Hi can you please tell how to extract 'fields' from json data?? I need them for displaying chart.

    var fields = cpuStore.reader.meta.fields;//;//

    var series = [];
    for(var i=1;i<fields.length;i++){
    // console.log(i);
    var newSeries = new Ext.chart.LineSeries({
    type: 'line',
    displayName: fields[i].name,
    yField: fields[i].name,
    xField: fields[0],
    style: {
    mode: 'stretch',
    color: this.chartColors[i+1]
    cpuChart.series = series;

    Here cpuStore is JsonStore and reader property has DataReader and json data is getting loaded before function is getting called. I have written above code on button click but its giving me error in that 'fields' is undefined in for loop. Plz help me!

  5. #5
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Boise, ID


    Are you needing a list of all of the keys?
    Perhaps decode the JSON: o = Ext.util.JSON.decode(JSON_STRING) > object
    Then Ext.iterate to read out the keys.
    Ext.each(o, function(key, value, obj){

  6. #6


    I dont understand the decode JSON step. Can you please elaborate. I am quite new to Extjs.

Similar Threads

  1. Converting to JSON for server side submission
    By techakone in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 30 Jan 2011, 10:38 PM
  2. Converting json to java object using struts json plugin
    By riya_phoenix in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 16 Dec 2009, 5:08 PM
  3. converting json object to xml
    By bhanu prakash dasari in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Mar 2009, 11:39 PM
  4. Converting JSON Data to a Record
    By Vikram1507 in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 18 Feb 2009, 2:35 AM
  5. converting xml to json
    By antimatter15 in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 30 Sep 2007, 11:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts