2017-02-13 102 views
0

我有這樣的JSON:{message:"a"}我如何從json獲得價值?

我通過AJAX發送請求,然後獲取響應:

<script> 
     $(document).ready(function(){ 
      $("#l").click(function(){ 
       $.ajax({ 
        url:"index/judement", 
        type:"POST", 
        dataType:"json", 
        contentType:"application/json;charset=UTF-8", 
        data:JSON.stringify({ 
         number:$("#number").val(), 
         password:$("#password").val() 
        }), 
        success: function (data) { 
         alert(JSON.stringify(data)); 
        }, 
        error: function() { 
         alert("..."); 
        } 
       }); 
      }); 
     }) 
    </script> 

然後我得到這個: enter image description here 但我只想得到a!不是所有的json!我應該怎麼做?

回答

1

試試這個刪除JSON.stringify(),這樣你會得到的值對象不是string

試試這個

alert(data.message); 

這隻會提醒,

如果您將使用

alert(JSON.stringify(data.message)); 

它會提醒 「一」

+1

你沒事 –

0

試試這個:

alert(JSON.stringify(data.message)); 
+0

哦!這麼簡單,我google兩個多小時都找不到解決方案! –