1

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)
7
  • 1
    Use $.parseJSON(), it should provide a polyfill for browsers that don't support JSON.parse(). Commented Jul 10, 2017 at 17:33
  • @ochi There are quotes around it, so it's a JSON string for a 2D array. Commented Jul 10, 2017 at 17:34
  • 1
    What browser are you using that doesn't support JSON.parse()? MDN says that it's compatible with IE8. Commented Jul 10, 2017 at 17:35
  • 1
    if you can't use JSON.parse can you use eval? If so check out this post: stackoverflow.com/questions/1843343/json-parse-vs-eval Commented Jul 10, 2017 at 17:41
  • 1
    myArr = eval(yourString); Only use values of yourString that you have created carefully yourself. Commented Jul 10, 2017 at 17:41

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.