我收到来自我的 WCF 服务的 JSON 字符串响应。我想将此 JSON 解析为相应的对象。所以我做了如下。
$.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.");
}
}
});
如何解析这个 JSON 数据。我们可以使用 JQuery 来做到这一点吗?