0
我做一个简单的GET使用jQuery像这样jQuery的无法解析JSON
var jqxhr = $.get("http://localhost/path/list", function() {
alert("success");
}, "json")
.done(function() { alert("second success"); })
.fail(function(jqXHR, textStatus, errorThrown){
console.dir(jqXHR);
}
);
的服务器状态200我能够解析它作为一个有效的JSON像我能够返回以下JSON在这里做:http://www.freeformatter.com/json-formatter.html。但总是调用失败方法。如果我将dataType更改为“text”,则调用成功方法。所以我认为jquery无法将响应解析为有效的json。什么可能是错的?
{
'root': {
'status': [
{
'Entity': 'user',
'InstanceId': '1',
'ModifiedAt': 'null',
'ModifiedBy': 'null',
'CreatedAt': 'null',
'CreatedBy': '1',
'Status': 'approval',
'AssignedFor': 'null',
'AssignedTo': '1',
'PatternName': 'approval'
},
{
'Entity': 'user',
'InstanceId': '2',
'ModifiedAt': 'null',
'ModifiedBy': 'null',
'CreatedAt': 'null',
'CreatedBy': '1',
'Status': 'start',
'AssignedFor': 'null',
'AssignedTo': '1',
'PatternName': 'input'
}
],
'count': 2
}
}
这是无效的JSON。字符串和键必须在**双**引号中。尝试http://jsonlint.org/。您链接到的页面上的信息(JavaScript允许使用单引号)不正确(可能他们会将对象文字与JSON混淆,谁知道呢)。 –
无效的JSON。检查json http://jsonlint.com/ – som
dughh!没有意识到工作到深夜!我应该记得使用http://jsonlint.org/。非常感谢! – user1076371