I get this error when debugging my highcharts javascript code via Firebug. Here are the relevant lines of code:
var valpair = [parseInt(items[0]),cumulative];
rain_series.data.push(JSON.parse(valpair));
items[0]
is just "1234567"
, and if I add console.log(valpair)
to my code, I get this output: [1234567, 0]
which seems to be valid JSON. Nevertheless, I'm stuck on my error (I searched for a solution, but didn't find one for my case).
Anyone here who knows what I'm doing wrong?
It's because you're using JSON.parse
to try to parse an array, which is not going to work. Just get rid of the JSON.parse
, and this should work as expected.
When you call JSON.parse
on something that's not a string, it's going to coerce it to a string by calling .toString()
on it. If valpair = [1234567, 0]
, then valpair.toString()
is going to yield 123457,0
(this is probably dependent on the JS engine: I get 123457,0
in Chrome). This is invalid JSON: the "unexpected non-whitespace character" is the comma.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With