0

I have a JSON string , I want to get value of JSON string property.I try

$.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) {
        var obj = $.parseJSON(data.d);
        alert(obj.TRANSACTION_NAME);
    },
    error: function (data) {
        alert("Error");
    }
});

But it gets error undefined . I use jQuery-2.1.3.min.js

Samurai
  • 3,724
  • 5
  • 27
  • 39
Headshot
  • 423
  • 1
  • 6
  • 22
  • Use `console.log(data);` and post your json data... – Hackerman May 16 '15 at 02:19
  • 2
    *"but it's get error undefined"* What does that mean? Are you getting `undefined` in the `alert`? Or are you really getting an error? We can't tell you how to access your structure if we don't know what it looks like. Given that you are the only one that can actually run the code, you are the best person to debug it. Learn how to debug, so that you can help yourself: https://developer.chrome.com/devtools/docs/javascript-debugging – Felix Kling May 16 '15 at 02:20
  • I get error in alert , it's show `undefined` . JSON data as `{"d":"[{\"FULL_NAME\":\"Android\",\"TRANSACTION_NAME\":\"Lisence\",\"FLAG\":false}]"}` – Headshot May 16 '15 at 02:49
  • Well, `d` is an array. The array doesn't have a `TRANSACTION_NAME` property. The first element it contains has that property. – Felix Kling May 16 '15 at 04:28

1 Answers1

0

$.parseJSON is not needed, jQuery parses the json automatically if you specify it as the contentType.

Brad M
  • 7,857
  • 1
  • 23
  • 40