0
我得到這個JSON從我的REST:REST和JQuery請求
{"users":[{"id_user":"1","firstname":"Admin","lastname":"Admin","mail":"[email protected]","password":"admin"}]}
,並與後續代碼我想解析JSON響應。
$.getJSON("http://localhost/REST/users",
function(data) {
var jsonData = JSON.parse(data);
for (var i = 0; i < jsonData.counters.length; i++) {
var counter = jsonData.counters[i];
console.log(counter.counter_name);
}
});
,但在控制檯中我得到這個錯誤信息:由於您使用的getJSON
你不需要轉換
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
我希望你能幫助我=/
還添加dataType:「json」 – user3244721