我幾乎沒有json的經驗,我不確定我在這裏偏離教科書。我有一個非常簡單的json對象,我想解析它。它沒有爲data.user_status註冊一個值。我在哪裏錯了?未能正確解析json ...不確定這是什麼問題?
$('input#login_submit').click(function(event){
$.post("/login_ajax/", {post:1,username:$('input#ajax_username').val(), password:$('input[name=password]').val()}, //could also use $(this).serialize() here to capture all form inputs
function(data){
if(data.user_status==1){
......(functions happen)
},'json');
return false;
});
螢火顯示,我已經回到了
對象{user_status = 1,user_favorite = 1,flag_record = 1}
如何處理呢?
感謝
請在if語句前做一個console.log(data)。但從它的外觀來看,它應該是「1」而不是1 – corroded 2011-03-24 05:36:49
好吧我通過用$ .each方法遍歷數據對它進行了整理。那麼你總是需要迭代json對象,即使它只是一個只有一個條目的列表? – Ben 2011-03-24 05:38:46
當屬性的值是整數或浮點數時,引號是不必要的。 – CarlosZ 2011-03-24 05:38:53