-4

我有一个验证用户名/密码的功能:

这是 JSON 响应:

{"data":{"user_id":"2","auth_token":"x"},"result": {"errorcode":"","messages":"Success:Logged On","rstatus":1}}

我希望能够解析出 user_id、auth_token、errorcode、messages、rstatus

这是调用的 JQuery 代码:

function authenticate(userName, password) {
    $.ajax({
        url: 'index.php?action=login',
        type: 'POST',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        data: 'username=' + userName + '&password=' + password,
        dataType: 'json',
        async: true,
        success: function (response) {
            //i need to parse out the data here
        }
    });
}

任何建议,将不胜感激。

4

2 回答 2

1

怎么样:

var user_id = response.data.user_id, 
    auth_token = response.data.auth_token, 
    errorcode = response.result.errorcode, 
    messages = response.result.messages, 
    rstatus = response.result.rstatus;
于 2013-08-27T14:10:55.640 回答
1

尝试如下,

var user_id = response.data.user_id,
   auth_token = response.data.auth_token,
   errorcode = response.result.errorcode,
   messages = response.result.messages,
   rstatus = response.result.rstatus;
于 2013-08-27T14:11:28.813 回答