简体   繁体   English

不使用JSON.parse解析字符串

[英]Parse String Without using JSON.parse

Good day. 美好的一天。 I have an array that needs to be parsed in a JSON format. 我有一个需要以JSON格式解析的数组。 However, the browser object does not support JSON calls...unfortunately. 但是,不幸的是,浏览器对象不支持JSON调用。 Is there a way to brute force the script into a JSON parse without explicitly calling it? 有没有一种方法可以在没有显式调用的情况下将脚本强行强制进入JSON解析?

Essentially, I am calling data from a SQL tbl and need to retrieve the data in order to make a table. 本质上,我从SQL tbl调用数据,并且需要检索数据才能创建表。 I need the array parsed in order to make a html table into rows and columns. 我需要解析数组以使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)

Use $.parseJSON() . 使用$.parseJSON() If the browser doesn't support JSON.parse() , it provides a polyfill. 如果浏览器不支持JSON.parse() ,它将提供一个polyfill。

Make sure you're using jQuery 1.11 or higher. 确保您使用的是jQuery 1.11或更高版本。 Earlier versions of jQuery used code equivalent to eval() for this polyfill, so it was dangerous. jQuery的早期版本为此polyfill使用了等效于eval()代码,因此很危险。 jQuery 1.11 has better validation of the input. jQuery 1.11可以更好地验证输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM