Py学习  »  Jquery

如何在JQuery中读取复杂的JSON Stringify数据?

Liam neesan • 4 年前 • 338 次点击  

我正在显示消息 电子邮件“xxx@gmail.com”已被接收 从这个JSON

{"readyState":4,"responseText":"{\"Message\":\"The request is invalid.\",\"ModelState\":{\"\":[\"Name xxx is already taken.\",\"Email 'xxx@gmail.com' is already taken.\"]}}","responseJSON":{"Message":"The request is invalid.","ModelState":{"":["Name xxx is already taken.","Email 'xxx@gmail.com' is already taken."]}},"status":400,"statusText":"Bad Request"}

我已经查过我以前的问题了 link . 我试了同样和不同的类型也像下面。但我失败了

fail(function (showError) {
        console.log('Signup failed');
        console.log('full error = ' + JSON.stringify(showError));
        var response = JSON.stringify(showError);
        console.log("response error = "+JSON.stringify(response.responseText.ModelState));

        console.log('Message error = ' + JSON.parse(showError.responseText).Message);
        console.log('ModelState error = ' + JSON.parse(showError.responseText).ModelState[0]);
        //console.log('ModelState error val= ' + JSON.parse(showError.responseText).ModelState[0].val);
        console.log('ModelState error text= ' + JSON.parse(showError.responseText).ModelState[0].text);
    });
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52687
 
338 次点击  
文章 [ 1 ]  |  最新文章 4 年前
tymeJV
Reply   •   1 楼
tymeJV    5 年前

ModelState 是以空字符串作为第一个键(包含错误数组)的对象,因此可以执行以下操作:

let errors = JSON.parse(showError.responseText).ModelState[""];