我可以成功取回看起来像 JSON 对象的内容,但是在解析它时出现非空白错误,当我不解析它时,我无法访问这些元素。基本上,我只想访问 JSON 中的每个元素并显示它。这是代码:(代码下方是我返回的 JSON(或看起来是 JSON)
$('#cardText').change(function(){
if($('#cardText').val().trim().length == 9)
{
$.ajax({
url: 'components/Person.cfc',
//GET method is used
type: "POST",
//pass the data
data: {
method: "getGroup",
uid: $('#cardText').val(),
},
success: function(response) {
//obj = jQuery.parseJSON(response); -- I get a non-whitespace error if I do this
var Col1 = response.COLUMNS[0]; -- this gives me response.Columns is undefined
$('#form_result').html(response);
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
}
});
返回数据:
{
"COLUMNS": ["PLAN", "NAME", "ID", "ISSUE", "TYPE", "LASTUSED", "BALANCE"],
"DATA": [["DINING STAFF CAFE 1919 ", "YOUNG, MARIA ", 8.03976343E8, "2001-04-02", 2.0, "2012-01-27", 1]]
}
来自记事本(数据有限) {"COLUMNS":["PLAN","NAME"],"DATA":[["DINING STAFF CAFE 1919 ","YOUNG, MARIA "]]}