Sachi Tekina
Sachi Tekina

Reputation: 1810

Accessing Value of JSON and use it in Highcharts

I have this JSON data, how do I access/get the values of "dateTimeRead", "rain_intensity" and "rain_cum"?

[
        {
            "dev_id": 118,
            "cell_num": "09175505376",
            "posx": "8.933333",
            "posy": "125.516667",
            "elevation": "0",              
            "remarks": "07/11/14/battery and signal are OK..UNATTENDED/system might be on hang state/need to reset arQ",
            "servernum": "09178747368",
            "imei_num": "300234011172910",
            "is_ftp": false,
            "date_calibrated": null,
            "date_installed": null,
            "errcode": null,
            "data": [
                {
                    "dateTimeRead": "2015-07-07 08:30:32",
                    "wind_speed": "4.7",
                    "rain_value": "0.00",
                    "rain_intensity": "0",
                    "rain_cum": "9566.21",
                    "soil_moisture1": "24.18",
                    "soil_moisture2": "62.76",
                    "rain_duration": "0",
                    "wind_speed_max": "10.3",
                    "sunshine_count": "0",
                    "sunshine_cum": "0",
                    "wind_direction_max": "301",
                    "air_temperature": "30.0",
                    "air_pressure": "1005.08",
                    "wind_direction": "130"                      
                }
            ]
        }
    ]

Tried this so far:

...    
success: function (e) {
        var t = e,
            a = [],
            o = [];
        $.map(t, function (e) {
            var t = e["data"].dateTimeRead;
            a.push([t, e["data"].rain_cum]), o.push([t, e["data"].rain_intensity])
        });
        console.log(t);

Here's the fiddle for reference. Any help is appreciated!

Upvotes: 0

Views: 47

Answers (1)

Raghavendra
Raghavendra

Reputation: 3580

data is an array

you have to loop it. eg:

$.map(t, function (e) {
var data = e.data;
for(i=0;i<data.length;i++) {
    var dataEl = data[i];
    var t = dataEl.dateTimeRead;
    a.push([t, dataEl.rain_cum]), o.push([t,dataEl.rain_intensity])
}

});

Upvotes: 1

Related Questions