I have the following Json object:
Object {success: false, errors: "{"email": [{"message": "Enter a valid email address.", "code": "invalid"}]}"}
This is response of Django errors.as_jason
method. I need to process the error message Enter a valid email address. I'm using jQuery. I tried many ways but with no success. json.errors
return this
{"email": [{"message": "Enter a valid email address.", "code": "invalid"}]}
but then json.errors.message
return undefined
and I didn't find a way to get it correct.
How I can get the message only?
If errors, in your case, is represented by a string, you may need to do the following:
JSON.parse(json.errors).email[0].message
Well, that's what I'd do, assuming I'm reading your message right.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.