Jquery parseJSON失败 - “意外令牌o”

时间:2014-10-20 17:47:52

标签: javascript jquery ajax json

我想为一些JSON数据做一个非常简单的AJAX请求然后解析它。我使用的代码如下:

$.get('/ajax/search/DSB.json', function (data) {
    searchData=$.parseJSON(data);
});

我收到一个错误:“意外的令牌o。”我已经验证有问题的文件是有效的JSON。我也用Google搜索了答案 - 每个有这个问题的人都将javascript对象传递给JSON解析器,这显然是多余的。但是,我不确定在这种情况下问题是什么。想法?

这是JSON,所以你可以检查它们是否有效(它是)。

{
  "numCols": 2,
  "colNames": [
    "Disability Level",
    "Region"
  ],
  "colWidths": [
    200,
    null
  ],
  "colFilters": [
    [
      "",
      "All Disability Types",
      "Not Significantly Disabled",
      "Significantly Disabled"
    ],
    [
      "",
      "All Regions",
      "East Region",
      "North Central Region",
      "South Central Region",
      "West Region"
    ]
  ],
  "table": [
    [
      "Significantly Disabled",
      "North Central Region",
      1000013
    ],
    [
      "Not Significantly Disabled",
      "All Regions",
      1000006
    ],
    [
      "Significantly Disabled",
      "All Regions",
      1000011
    ],
    [
      "Significantly Disabled",
      "West Region",
      1000012
    ],
    [
      "All Disability Level",
      "West Region",
      1000002
    ],
    [
      "All Disability Level",
      "South Central Region",
      1000004
    ],
    [
      "Not Significantly Disabled",
      "South Central Region",
      1000009
    ],
    [
      "All Disability Level",
      "All Regions",
      1000001
    ],
    [
      "Not Significantly Disabled",
      "West Region",
      1000007
    ],
    [
      "Significantly Disabled",
      "East Region",
      1000015
    ],
    [
      "Not Significantly Disabled",
      "East Region",
      1000010
    ],
    [
      "All Disability Level",
      "East Region",
      1000005
    ],
    [
      "Significantly Disabled",
      "South Central Region",
      1000014
    ],
    [
      "All Disability Level",
      "North Central Region",
      1000003
    ],
    [
      "Not Significantly Disabled",
      "North Central Region",
      1000008
    ]
  ],
  "names": [
    [
      1000013,
      "Significantly Disabled Participants in North Central Region"
    ],
    [
      1000006,
      "Not Significantly Disabled Participants in All Regions"
    ],
    [
      1000011,
      "Significantly Disabled Participants in All Regions"
    ],
    [
      1000012,
      "Significantly Disabled Participants in West Region"
    ],
    [
      1000002,
      "All Disability Level Participants in West Region"
    ],
    [
      1000004,
      "All Disability Level Participants in South Central Region"
    ],
    [
      1000009,
      "Not Significantly Disabled Participants in South Central Region"
    ],
    [
      1000001,
      "All Disability Level Participants in All Regions"
    ],
    [
      1000007,
      "Not Significantly Disabled Participants in West Region"
    ],
    [
      1000015,
      "Significantly Disabled Participants in East Region"
    ],
    [
      1000010,
      "Not Significantly Disabled Participants in East Region"
    ],
    [
      1000005,
      "All Disability Level Participants in East Region"
    ],
    [
      1000014,
      "Significantly Disabled Participants in South Central Region"
    ],
    [
      1000003,
      "All Disability Level Participants in North Central Region"
    ],
    [
      1000008,
      "Not Significantly Disabled Participants in North Central Region"
    ]
  ]
}

1 个答案:

答案 0 :(得分:-1)

删除您的数据已输入的.parseJSON(data)函数为json

如果joson是字符串格式,则此函数不起作用,但是您的示例json类型是json而不是字符串如果您使用parseJSON(data)返回此函数错误此function工作集仅适用于json string