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

      0  

    Default Accessing a field of json data

    Accessing a field of json data


    I am getting below json data in jsondata field:

    HTML Code:
    {
        "data": [{
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1012620
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 1003278
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 457615
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 660982
            },
            {
                "Part": "other",
                "ProductionCounts": 1571985
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 899308
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 1597379
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 0
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 0
            },
            {
                "Part": "other",
                "ProductionCounts": 2196254
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 652255
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 118862
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 314481
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 0
            },
            {
                "Part": "other",
                "ProductionCounts": 2106794
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 799850
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 787854
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 572825
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 586796
            },
            {
                "Part": "other",
                "ProductionCounts": 1699898
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1098905
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 849032
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 680223
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 676436
            },
            {
                "Part": "other",
                "ProductionCounts": 2126999
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1182160
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 1096124
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 307723
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 0
            },
            {
                "Part": "other",
                "ProductionCounts": 2339177
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 442606
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 1188054
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 232819
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 437088
            },
            {
                "Part": "other",
                "ProductionCounts": 2123290
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 804017
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 701323
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 658470
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 400048
            },
            {
                "Part": "other",
                "ProductionCounts": 1453187
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1976932
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 179347
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 493326
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 366893
            },
            {
                "Part": "other",
                "ProductionCounts": 1537608
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1220153
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 651824
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 543190
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 0
            },
            {
                "Part": "other",
                "ProductionCounts": 3195743
            }]
        },
        {
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 0
            },
            {
                "Part": "1.75 L Marg Mix (PET)",
                "ProductionCounts": 0
            },
            {
                "Part": "1.75 L Authentics (PET)",
                "ProductionCounts": 0
            },
            {
                "Part": "1.0 L Margarita Mix / PET",
                "ProductionCounts": 0
            },
            {
                "Part": "other",
                "ProductionCounts": 0
            }]
        }],
        "dateArray": ["2011-01-01",
        "2011-02-01",
        "2011-03-01",
        "2011-04-01",
        "2011-05-01",
        "2011-06-01",
        "2011-07-01",
        "2011-08-01",
        "2011-09-01",
        "2011-10-01",
        "2011-11-01"],
        "xAxis":"Part",
        "yAxis":"ProductionCounts",
        "interestingMoments": []
    }
    I am getting the xAxis value in one variable like
    var xAxis = jsonData.xAxis;
    Value is coming fine in variable but when I am trying to access value like this.
    jsonData.data[0].data[0].xAxis -- > it is giving me undefined instead of correct value.

    What I am doing wrong here? What should be the correct method to access that value ?

  2. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    There is nothing weird with that, you are trying to get an undefined value:

    Code:
    {
        "data": [{
            "data": [{
                "Part": "1.75 L ICON (Glass)",
                "ProductionCounts": 1012620
            },

    data[0].data[0] has only two available properties:
    • Part
    • ProductionCounts
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


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

      0  

    Default


    Yes but those 2 values can be different each time in json response so I am assigning that value in a variable xAxis and then using it. Why it is not taking that value as variable.

Thread Participants: 1

Tags for this Thread