Skip to content
Advertisement

How to get data from JSON array JavaScript

I want to push the data from piedatalist which contains two attributes, value and key and I want to pass to jqplot like this [key,value] to render the chart but it doesn’t work.

JavaScript

Advertisement

Answer

The JSON at the start can’t just be pasted into the code. It’s a string, but there are newlines which break strings, and double-quote characters which would end the string also.

You can just paste in the JSON as a variable instead of a string and JavaScript will allow it just fine:

JavaScript
Advertisement