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

      0  

    Default Accessing field of json object through variable

    Accessing field of json object through variable


    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
            }]
        },
        
    ],
        "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 want to access the value of json object. Field name of json object will be different each time . In this sample json I am having 2 field "Part" and "ProductionCounts" but it may be something else next time when I am getting the json so I am sending the field name in xAxis and yAxis with json but when I am trying to access the jsonData.data[0].data[0].xAxis , it is giving me undefined instead of value. I can't access like jsonData.data[0].data[0].Part as field name will be different each time so I am trying to access it through variable .

    Please let me know how can I access the json object field values without knowing the name of field or through variable.


  2. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    if you store your response in
    Code:
    var jsonData = {//your response object};
    you should acces for example your first item:
    Code:
    jsonData.data[0].data[0][jsonData.xAxis]

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    23
    Vote Rating
    0
    manvinder is on a distinguished road

      0  

    Default


    First get the name of fields xAxis and yAxis first like this
    var xAxisValue = jsonData.xAxis;
    var xAxisValue = jsonData.yAxis


    Than search for the value like this


    var val1 = jsonData.data[0].data[index].xAxisValue;
    var val2 = jsonData.data[0].data[index].yAxisValue;

    I didn't tested this, but It should work.

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar