arios
arios

Reputation: 185

Parse String Without using JSON.parse

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)

Upvotes: 1

Views: 2451

Answers (1)

Barmar
Barmar

Reputation: 780974

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.

Upvotes: 3

Related Questions