jQuery嵌套响应数组问题
我有一个验证用户名/密码的函数: 以下是JSON响应: {数据:{user_id:2,auth_token:x},结果:{errorcode:,消息:成功:登录,rstatus:1} 我希望能够解析出用户id、身份验证令牌、错误代码、消息、rstatus 以下是调用的JQuery代码:jQuery嵌套响应数组问题,jquery,ajax,json,Jquery,Ajax,Json,我有一个验证用户名/密码的函数: 以下是JSON响应: {数据:{user_id:2,auth_token:x},结果:{errorcode:,消息:成功:登录,rstatus:1} 我希望能够解析出用户id、身份验证令牌、错误代码、消息、rstatus 以下是调用的JQuery代码: function authenticate(userName, password) { $.ajax({ url: 'index.php?action=login', ty
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
}
});
}
如有任何建议,我们将不胜感激。如何:
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;
试着像下面这样
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;
错误代码、消息和rstatus来自response.result.:P@Vega-Bah,应该检查一下,查看JSON以快速:p这可能会在将来帮助您。请仔细阅读。。谢谢格雷库斯。。。成功了!