在我的情况下,如何从Json Stringify读取值? [英] How to read the value from Json Stringify in my case?

查看:457
本文介绍了在我的情况下,如何从Json Stringify读取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我验证用户登录后,如果登录失败,则会显示以下错误消息

After I validate user login, if it failed it will show the following error message

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 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."}

我只想显示The user name or password is incorrect条消息

我已经检查了 jQuery-从JSON Stringify获取价值链接

推荐答案

您必须解析responseText属性,因为它是JSON字符串.

You have to parse the responseText property since it's a JSON string.

console.log(JSON.parse(showError.responseText).error_description);

// or using bracket notation
console.log(JSON.parse(showError.responseText)['error_description']);

var showError = {"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"} ;

console.log(JSON.parse(showError.responseText).error_description);

这篇关于在我的情况下,如何从Json Stringify读取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆