未捕获的SyntaxError:尝试解析JSON字符串时出现意外的令牌e

时间:2015-07-30 00:02:49

标签: javascript json

我尝试使用JSON.parse返回下面字符串的javascript对象。但是,我收到“Uncaught SyntaxError:Unexpected token e”。

{
    "__type": "HRIS.oHRData, HRIES, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
    "TPDDListValue": new Ajax.Web.DataSet([]),
    "DPDDListValue": new Ajax.Web.DataSet([]),
    "TopDataValue": new Ajax.Web.DataSet([
        new Ajax.Web.DataTable([
            ["HID","System.String"],
            ["HFrName0","System.String"],
            ["HFtName0","System.String"],
            ["HGFName0","System.String"],
            ["HFmName0","System.String"],
            ["TID","System.Byte"]
        ],[
            ["123456789","ABCD1","ABCD2","ABCD3 ","ABCD4",2]
        ])
    ]),
    "DownDataValue": new Ajax.Web.DataSet([]),
    "MenuDataValue": new Ajax.Web.DataSet([]),
    "SearchReturnValue": new Ajax.Web.DataSet([]),
    "Result": null,
    "NewID": "NoID",
    "AffectedRecords": 0
}

我使用此代码:

var text= 'the json string here';

var obj=JSON.parse(text);

我认为问题是JSON无法识别其类型 新的Ajax.Web.DataSet([])

我该如何解决这个问题?

任何想法都表示赞赏。

非常感谢,

1 个答案:

答案 0 :(得分:1)

如果您真的只是将其放入代码中,则不需要引号,也不需要解析它:

var theObject = {
    "__type": "HRIS.oHRData, HRIES, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
    "TPDDListValue": new Ajax.Web.DataSet([]),
    "DPDDListValue": new Ajax.Web.DataSet([]),
    "TopDataValue": new Ajax.Web.DataSet([
        new Ajax.Web.DataTable([
            ["HID","System.String"],
            ["HFrName0","System.String"],
            ["HFtName0","System.String"],
            ["HGFName0","System.String"],
            ["HFmName0","System.String"],
            ["TID","System.Byte"]
        ],[
            ["123456789","ABCD1","ABCD2","ABCD3 ","ABCD4",2]
        ])
    ]),
    "DownDataValue": new Ajax.Web.DataSet([]),
    "MenuDataValue": new Ajax.Web.DataSet([]),
    "SearchReturnValue": new Ajax.Web.DataSet([]),
    "Result": null,
    "NewID": "NoID",
    "AffectedRecords": 0
};

这将要求提供Ajax对象的任何服务都存在。