2013-07-17 63 views
0

我有以下json響應我需要對象通過JavaScript提醒錯誤。提醒JSON響應

{"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":{null},"errors":{"msisdn":"num\u00e9ro de t\u00e9l\u00e9phone non valide"}} 

我米,json新手,我無法找到一個方法來提醒我的控制器呈現我的錯誤。

許多THX

+1

''aaData「:{null}'是無效的JSON。否則:'JSON.parse(string)'... – 2013-07-17 09:39:02

+0

你能夠得到與你收到的響應相對應的JavaScript對象嗎? –

回答

0

試試這個:

// your json data 
var s = '{"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":"{null}","errors":{"msisdn":"phone non valide"}}'; 

// change in json object 
var obj = JSON.parse(s); 

// get errors value 
console.log(obj.errors); 

請確保您有有效的JSON數據

0

嘗試用下面的代碼

var j = '{"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":null,"errors":{"msisdn":"num\u00e9ro de t\u00e9l\u00e9phone non valide"}}'; 
var a = JSON.parse(j); 
alert(a.errors.msisdn); 

它會顯示錯誤的MSISDN財產的消息,如MSISDN是錯誤的子屬性。