0

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?

4
  • String or Object ? Commented Sep 17, 2016 at 14:51
  • How would I tell? I am returning it directly into a function, so i think object. Commented Sep 17, 2016 at 14:52
  • console.log(typeof data) Commented Sep 17, 2016 at 14:52
  • JSON.parse(data).success Commented Sep 17, 2016 at 14:53

1 Answer 1

1

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

JSON.parse(data).success
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. That was the issue. I will mark your answer as correct as soon as I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.