Parse Json data in Jquery Parse Json data in Jquery ajax ajax

Parse Json data in Jquery


Try this code.

$.ajax({    /* type : "POST", */    url: "launchapptest",    /* contentType: "application/json; charset=utf-8", */    data: "processDateInput=" + processDate,    dataType: "json",    async: true,    success: function (result) {        var od = JSON.stringify(result);        var obj = JSON.parse(od);        $.each(obj, function (index, value) {            console.log(obj[index][0].percentageCompleted);            console.log(obj[index][0].processRunning);            console.log(obj[index][0].remainingTime);            console.log(obj[index][0].successBatchCount);            console.log(obj[index][0].totalBatchCount);            console.log(obj.processDateInput);            $.each(obj[index][0].dateProcessed, function (ind, val) {                console.log(val);            })        });    }});


When you specify the dataType as JSON, jQuery will automatically parse it for you. Parsing it again as you are (multiple times, even) will cause issues. Try this:

success: function(result) {    console.log(result.od);    console.log(result.od[0].percentageCompleted);}

I'm not entirely sure what your $.each loop is trying to do as there is no tagName property in your object.


What is the is the return data of your AJAX call

is like this then

{    "od": [        {            "dateProcessed": [                "09/11/2014",                "09/12/2014"            ],            "percentageCompleted": 25,            "processRunning": 0,            "successBatchCount": 0,            "totalBatchCount": 0        }    ],    "processDateInput": "12/11/2014"}

you can parse it like this

var json = JSON.parse(result);            var od = json['od'];            var processDateInput = json['processDateInput'];            $.each(od, function(index, value){                console.log(value, index);            });

hope it would work on you.