0

Good day. I have an array that needs to be parsed in a JSON format. However, the browser object does not support JSON calls...unfortunately. Is there a way to brute force the script into a JSON parse without explicitly calling it?

Essentially, I am calling data from a SQL tbl and need to retrieve the data in order to make a table. I need the array parsed in order to make a html table into rows and columns.

Any help is most appreciated.

Current Array No Parsing

"[["0","Accumulation is at 100% Full","78"],["0","Accumulation is at 50% Full","77"],["1","Accumulation Time Purge Warning","79"]]"

Desired Array with Parsing

  0:Array(3)
    0:"0"
    1:"Accumulation is at 100% Full"
    2:"78"
    length:3
    __proto__:Array(0)
  1:Array(3)
    0:"0"
    1:"Accumulation is at 50% Full"
    2:"77"
    length:3
    __proto__:Array(0)
  2:Array(3)
    0:"1"
    1:"Accumulation Time Purge Warning"
    2:"79"
    length:3
    __proto__:Array(0)
arios
  • 165
  • 1
  • 15
  • 1
    Use `$.parseJSON()`, it should provide a polyfill for browsers that don't support `JSON.parse()`. – Barmar Jul 10 '17 at 17:33
  • @ochi There are quotes around it, so it's a JSON string for a 2D array. – Barmar Jul 10 '17 at 17:34
  • 1
    What browser are you using that doesn't support `JSON.parse()`? MDN says that it's compatible with IE8. – Barmar Jul 10 '17 at 17:35
  • @Barmar I suppose – blurfus Jul 10 '17 at 17:37
  • 1
    if you can't use JSON.parse can you use eval? If so check out this post: https://stackoverflow.com/questions/1843343/json-parse-vs-eval – David Jul 10 '17 at 17:41
  • 1
    `myArr = eval(yourString);` Only use values of yourString that you have created carefully yourself. – James Jul 10 '17 at 17:41
  • @Barmar $.parseJSON() works, thanks.... I am using a Wonderware application which is a SCADA software that has an internal web browser object which says its an IE 11.096. It should have read JSON.parse, but it didn't. – arios Jul 10 '17 at 17:42

1 Answers1

3

Use $.parseJSON(). If the browser doesn't support JSON.parse(), it provides a polyfill.

Make sure you're using jQuery 1.11 or higher. Earlier versions of jQuery used code equivalent to eval() for this polyfill, so it was dangerous. jQuery 1.11 has better validation of the input.

Barmar
  • 741,623
  • 53
  • 500
  • 612