0

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 を使用してこれを行うことができますか。

4

2 に答える 2

0

getJSON関数を次のように使用します

      $.getJSON('http://URL/Service.svc/LoginValidation?',function(data)
       {
        var JSON=data.replace(/^"|"$/g, '\''); 
        UserID = JSON.UserID;
        ClientID = JSON.ClientID;
        DomainName = JSON.DomainName;
        AuthenticationKey = JSON.AuthenticationKey;
           // do remaining stuffs
       })  
    });
于 2012-07-10T08:00:22.383 に答える
0

呼び出しオプションを設定dataType: 'json'するだけで$.ajax()、jQuery がそれを解析し、デコードされたオブジェクトをsuccessハンドラーに提供します。

于 2012-07-10T07:53:47.890 に答える