Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在我的例子中,如何从Json Stringify读取值?_Jquery_Json_Stringify - Fatal编程技术网

Jquery 在我的例子中,如何从Json Stringify读取值?

Jquery 在我的例子中,如何从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

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

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."}
我只想显示
用户名或密码不正确
信息


我已经检查了这个链接,因为它是一个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我已经试过了兄弟,它是未定义的