console.log(xhr.responseText);
输出:
{"non_field_errors":["My error msg"]}
如何显示 non_field_errors
的第一个错误?
console.log(xhr.responseText['non_field_errors'])
不起作用
最佳答案
您需要将 responseText
中的 JSON 字符串解析为对象,然后才能访问其属性。试试这个:
var json = JSON.parse(xhr.responseText);
console.log(json.non_field_errors[0]); // = "My error msg"
关于jquery - 在 jQuery 中显示 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36935855/