I am receiving JSON string response from my WCF service. I wanna parse this JSON to respective objects. So i have done like below.
$.ajax({
type: 'GET',
url: 'http://URL/Service.svc/LoginValidation?',
success: function(response, status, xhr) {
if (response != "") {
var JSON=response.replace(/^"|"$/g, '\''); // replace Start and End double Quotes with single quotes. becze JSON string should be start and end with single quotes while parsing this.
var obj = JSON.parse(JSON); // Here is my problem. While accessing JSON variable here that automatically showing double quotes. so that here showing syntax error.
UserID = obj.UserID;
ClientID = obj.ClientID;
DomainName = obj.DomainName;
AuthenticationKey = obj.AuthenticationKey;
}
else {
alert("Invalid UserName or Password.");
}
}
});
How to parse this JSON data. can we do this using JQuery.
Just set
dataType: 'json'in your$.ajax()call options and jQuery will parse it and provide the decoded object to yoursuccesshandler.