0

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!

1 Answer 1

1

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])
}

});
Sign up to request clarification or add additional context in comments.

4 Comments

It returns an error: Uncaught TypeError: Cannot read property 'data' of undefined.
Now, how to use it in Highcharts?
@SachiTekina i am not familar with Highcharts. do you have link of that chart api?
No worries, figure it out! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.