1

Here I am dynamically getting a string like this:

  var datN="{y:12 ,marker: {symbol: 'url(http://abc.com//1446/t_23718.gif)'}},72.72727,83.333336";

I want to use it in HighChart api as graph data but this is not working. I have tried and got this that if the code was like this it would work:

  var datN=[{y:12 ,marker: {symbol: 'url(http://abc.com//1446/t_23718.gif)'}},72.72727,83.333336];

so how can I convert the first variable to work like the second one? I am new to javascript please help?

UPDATE

All I want is to convert the first string to object like second one (Second one is working correctly) . I have already tries JSON.parse and eval but they didnt work. So please help?

Navdroid
  • 1,541
  • 3
  • 25
  • 52

1 Answers1

3
var datArr = JSON.parse("[" + datN + "]");

This may not work across browsers because JSON.parse is not supported by all browsers. I think you could use jquery

var datArr = $.parseJSON("[" + datN + "]");

If it still does not work, you may try

var datArr = eval("[" + datN + "]");

Although this solution is not recommended.

Khanh TO
  • 48,509
  • 13
  • 99
  • 115