解析字符串而不使用JSON.parse

时间:2021-01-03 20:16:46

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?

美好的一天。我有一个需要以JSON格式解析的数组。但是,不幸的是,浏览器对象不支持JSON调用。有没有办法强制脚本进入JSON解析而不显式调用它?

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.

本质上,我从SQL tbl调用数据,需要检索数据才能生成表。我需要解析数组,以便将html表格分为行和列。

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)

1 个解决方案

#1


2  

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

使用$ .parseJSON()。如果浏览器不支持JSON.parse(),它会提供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.

确保您使用的是jQuery 1.11或更高版本。早期版本的jQuery使用了与此polyfill等效的eval()代码,因此它很危险。 jQuery 1.11有更好的输入验证。

#1


2  

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

使用$ .parseJSON()。如果浏览器不支持JSON.parse(),它会提供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.

确保您使用的是jQuery 1.11或更高版本。早期版本的jQuery使用了与此polyfill等效的eval()代码,因此它很危险。 jQuery 1.11有更好的输入验证。