ccdavies ccdavies - 2 months ago 18
jQuery Question

Accessing JSON data via jQuery

The following is returned through the variable

data
.

{"success":0,"errors":[],"field_errors":{"title":"This field is required.","url_title":"This field is required.","field_id_9":"This field is required.","field_id_229":"This field is required.","testimonial_import_id":"This field is required.","testimonial_display":"This field is required."},"entry_id":null,"url_title":null,"channel_id":"4"}


I am unable to access individual items.

I have tried:

data.success
data[0]
data[0].success


Can anyone point me in the right direction here?

Answer

You need to parse the JSON string using JSON.parse method for converting it to JavaScript object.

JSON.parse(data).success