我正在加载一个包含JSON对象的本地文件,该对象已经由jsonlint和freeformater验证,我在Firefox的控制台中收到not well-formed
错误。
我看了this question并尝试使用它,但它似乎不起作用。
这是文件中的文字:
{
"CallsStats": [
{
"name": "Sales",
"CallsWaiting": "1",
"OnInboundACDCalls": "0",
"LongestWaitTime": "00:01:14",
"LongestOnHoldTime": "N/A",
"Queue_Interval": {
"name": "CurrentShift",
"CallsAbandoned": "1",
"CallsEntered": "18",
"CallsAnswered": "16",
"AverageWaitTime": "00:01:09",
"AverageHoldTime": "00:00:29",
"AverageTalkTime": "00:03:42"
}
},
{
"name": "Marketing",
"CallsWaiting": "0",
"OnInboundACDCalls": "0",
"LongestWaitTime": "N/A",
"LongestOnHoldTime": "N/A",
"Queue_Interval": {
"name": "CurrentShift",
"CallsAbandoned": "0",
"CallsEntered": "0",
"CallsAnswered": "0",
"AverageWaitTime": "N/A",
"AverageHoldTime": "N/A",
"AverageTalkTime": "N/A"
}
},
{
"name": "Support",
"CallsWaiting": "14",
"OnInboundACDCalls": "14",
"LongestWaitTime": "00:04:42",
"LongestOnHoldTime": "00:02:48",
"Queue_Interval": {
"name": "CurrentShift",
"CallsAbandoned": "816",
"CallsEntered": "2696",
"CallsAnswered": "1349",
"AverageWaitTime": "00:03:36",
"AverageHoldTime": "00:00:13",
"AverageTalkTime": "00:03:27"
}
}
]
}
这是我的代码:
function loadJson() {
$(document).ready(function()
{
$.ajax(
{
url: 'sampledata.json',
dataType: 'application/json',
success:function(data) {
console.log(data);
}
}
);
});
}
我之前尝试使用$.getJSON
并获得相同的结果。
编辑问题
我尝试了James Montagne在评论中提出的建议(我认为$.getJSON
会自动做什么......这就是我得到的:
所以我意识到一些看不见的角色是个问题,我摆脱了它们。
现在我可以将文件作为文本加载并使用JSON.parse(data)
将其转换为JSON对象,但仍显示错误:
它可能是什么,我应该关注什么?