Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a JSON string , I want to get value of JSON string property.I try
JavaScript
$.ajax({
    type: "POST",
    url: "../BUS/WebService.asmx/GET_TRANSACTION_NEW",
    data: JSON.stringify(DTO),
    contentType: "application/json; charset=utf-8",
    dataType: 'json',
    success: function (data) {
        //console.log(data);
        var obj = $.parseJSON(data.d);
        alert(obj.DEPARTMENT_NAME);
    },
    error: function (data) {
        alert("Error");
    }
});

But it's not work , it's show alert
undefined
. This is console log data
HTML
Object {d: "[{"DEPARTMENT_ID":"D00000000001","DEPARTMENT_NAME"…"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false}]"}
d: "[{"DEPARTMENT_ID":"D00000000001","DEPARTMENT_NAME":"HR","DEPARTMENT_DES":"HR","EDIT_DATE":"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false},{"DEPARTMENT_ID":"D00000000002","DEPARTMENT_NAME":"ACCOUNT","DEPARTMENT_DES":"ACCOUNT","EDIT_DATE":"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false}]"
__proto__: Object

Give me some advices, thank you
Posted

1 solution

Your sample JSON is an array of object so obj is an array of object...
You have to access the actual values using array notation...
JavaScript
obj[0].DEPARTMENT_NAME

or
JavaScript
obj[1].DEPARTMENT_NAME
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900