Jquery 在我的例子中,如何从Json Stringify读取值?
验证用户登录后,如果失败,将显示以下错误消息 jqueryJquery 在我的例子中,如何从Json Stringify读取值?,jquery,json,stringify,Jquery,Json,Stringify,验证用户登录后,如果失败,将显示以下错误消息 jquery console.log('Full error = ' + JSON.stringify(showError)); console.log('test 1 =' + showError.responseText); 错误消息 Full error = {"readyState":4,"responseText":"{\"error\":\"invalid_grant\",\"error_description\":\"The us
console.log('Full error = ' + JSON.stringify(showError));
console.log('test 1 =' + showError.responseText);
错误消息
Full error = {"readyState":4,"responseText":"{\"error\":\"invalid_grant\",\"error_description\":\"The user name or password is incorrect.\"}","responseJSON":{"error":"invalid_grant","error_description":"The user name or password is incorrect."},"status":400,"statusText":"Bad Request"}
test 1 ={"error":"invalid_grant","error_description":"The user name or password is incorrect."}
我只想显示用户名或密码不正确
信息
我已经检查了这个链接,因为它是一个JSON字符串,所以您必须解析
responseText
属性
console.log(JSON.parse(showError.responseText).error_description);
// or using bracket notation
console.log(JSON.parse(showError.responseText)['error_description']);
var-shortError={“readyState”:4,“responseText”:“{”错误“:\”无效的授权“,\”错误描述“:\”用户名或密码不正确。\“}”,“responseJSON:{”错误“:”无效的授权“,”错误描述“:”用户名或密码不正确“,},”状态“:”400,“状态文本“:”错误请求“};
log(JSON.parse(shourror.responseText).error\u说明)代码>您可以使用JSON.parse方法以字符串格式解析JSON数据。它将返回一个JSON对象。在您的示例中
var response = JSON.stringify('{"readyState":4,"responseText":"{\"error\":\"invalid_grant\",\"error_description\":\"The user name or password is incorrect.\"}","responseJSON":{"error":"invalid_grant","error_description":"The user name or password is incorrect."},"status":400,"statusText":"Bad Request"}
')
var error_message = response.responseText.error_description
错误消息变量包含您的错误消息是否可以尝试console.log(淋浴错误.响应文本.错误描述)@Satya我已经试过了兄弟,它是未定义的