1. 程式人生 > >【已解決】Uncaught SyntaxError: Unexpected token o in JSON at position 1

【已解決】Uncaught SyntaxError: Unexpected token o in JSON at position 1

Uncaught SyntaxError: Unexpected token o in JSON at position 1

$.ajax({
     type:"POST",
     url:webbase + "/account/checkIfAuth.do",
     data:{},
     dataType:"json",
     async:false,
     success:function(res){
   
    console.log(res);
     
    var json =
jQuery.parseJSON(res); //錯誤
var json = res;//直接使用


if (json.errorCode == 200) {
if(json.data!=null){
ispas= json.data;
}
}
     }
  })

返回的資料已經是object型別,不需要再進行JSON.parse()轉換了,可以直接當作物件使用。