Reputation: 1211
I have a webservice and it returns json data like this..
{"d":"{\"RES\":[],\"STAT\":\"FAIL\",\"SID\":\"0\"}"}
how i can i read the STAT=FAIL from this. I wrote service in c#.
my script is
$.ajax({
type: "POST",
url: "http://localhost/EMRDMSService/Service.asmx/User_Login",
data: "{lg:" + JSON.stringify(GetLogDet) + "}",
// url: "http://localhost/EMRDMSService/Service.asmx/Permission_List",
// data: "{userid:" + JSON.stringify(GetLogDet) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
console.log(r.d.STAT);
}
});
But the r.d.STAT is undefined
?
Can anybody help me with this?
Upvotes: 0
Views: 91
Reputation: 10658
As said in some of the comments, {"d":"{\"RES\":[],\"STAT\":\"FAIL\",\"SID\":\"0\"}"}
isn't correct JSON. However, if you can't update the webservice, you could try this in your success
callback:
var d = JSON.parse(r.d);
console.log(d.STAT);
EDIT in response to OP edits r.d.STAT
will be undefined because d
is interpreted as a String, not a Object. That's why you'll have to parse it or update the webservice to remove the quotes around the value of d
.
Upvotes: 3