Al Ivon Al Ivon - 4 years ago 131
Javascript Question

jQuery - traversing through Json object

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download