Skip to main content
added 200 characters in body
Source Link
meskobalazs
  • 16.1k
  • 2
  • 44
  • 63

The actual error you get is because you should write var str = ... instead of string.

You could get the substrings containing the function, and evaluate them as a function using eval. However this could lead to serious security and other concerns. To quote Douglas Crockford:

The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.

If you really want to go down this road, you can do it using eval, but you have been warned :)

By the way, if you have parsed your JSON you could do this:

obj[0].getConnectorPosition = eval(obj[0].getConnectorPosition);

So you replace the previous string with the evaluated method.

The actual error you get is because you should write var str = ... instead of string.

You could get the substrings containing the function, and evaluate them as a function using eval. However this could lead to serious security and other concerns. To quote Douglas Crockford:

The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.

If you really want to go down this road, you can do it using eval, but you have been warned :)

The actual error you get is because you should write var str = ... instead of string.

You could get the substrings containing the function, and evaluate them as a function using eval. However this could lead to serious security and other concerns. To quote Douglas Crockford:

The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.

If you really want to go down this road, you can do it using eval, but you have been warned :)

By the way, if you have parsed your JSON you could do this:

obj[0].getConnectorPosition = eval(obj[0].getConnectorPosition);

So you replace the previous string with the evaluated method.

added 605 characters in body
Source Link
meskobalazs
  • 16.1k
  • 2
  • 44
  • 63

Functions are not legal in JSONThe actual error you get is because you should write var str = ... instead of string. 

You still could parse itget the substrings containing the function, but not withand evaluate them as a JSON parserfunction using - also I am quite sure there is a better way for whateval. However this could lead to serious security and other concerns. To quote Douglas Crockford:

The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.

If you really want to achieve.go down this road, you can do it using eval, but you have been warned :)

Functions are not legal in JSON. You still could parse it, but not with a JSON parser - also I am quite sure there is a better way for what you want to achieve.

The actual error you get is because you should write var str = ... instead of string. 

You could get the substrings containing the function, and evaluate them as a function using eval. However this could lead to serious security and other concerns. To quote Douglas Crockford:

The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.

If you really want to go down this road, you can do it using eval, but you have been warned :)

Post Undeleted by meskobalazs
Post Deleted by meskobalazs
Source Link
meskobalazs
  • 16.1k
  • 2
  • 44
  • 63

Functions are not legal in JSON. You still could parse it, but not with a JSON parser - also I am quite sure there is a better way for what you want to achieve.