0

I have an input on a form which stores values as an object.

jQuery('#inputId').val()

returns something like

'[{"Id":"123","Name":"A","PathOfTerm":"A","Children":[],"Level":0,"RawTerm":null},{"Id":"234","Name":"B","PathOfTerm":"B","Children":[],"Level":0,"RawTerm":null}]'

as one single string. Is there any way to either prevent this from automatically converting to a string (maybe not using .val?) or to convert this from a string to something I could work with?

7
  • So you want to have it as a object ? Commented May 16, 2017 at 13:03
  • 4
    you could JSON.parse this Commented May 16, 2017 at 13:04
  • Looks like it's returning JSON. Lucky for you most browsers have the function JSON.parse to convert it to an object Commented May 16, 2017 at 13:04
  • Possible duplicate of Parse JSON in JavaScript? Commented May 16, 2017 at 13:06
  • Possible duplicate of Convert JSON string to array of JSON objects in Javascript Commented May 16, 2017 at 13:06

1 Answer 1

5

Here you go

var array = JSON.parse(jQuery('#inputId').val());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.