2015-01-07 40 views
0

返回和功能,我得到它包含JSON結果得到控制器的JSON值

{ 
    "readyState":4, 
    "responseText":"{\"Success\":0,\"Failed\":0}", 
    "responseJSON":{ 
     "Success":0, 
     "Failed":0 
    }, 
    "status":200, 
    "statusText":"OK" 
} 

我怎樣才能把成功和失敗值的對象?

data.Successand JSON.parse(數據)不工作

+0

'JSON.parse(a.responseText).Success' – surajck

+0

請定義「不工作」。爲什麼不?你得到一個錯誤?你意想不到的結果?還有別的嗎? – Teemu

回答

1

你不需要解析因爲IS已經是一個對象:

var obj = {"readyState":4,"responseText":"{\"Success\":0,\"Failed\":0}","responseJSON":{"Success":0,"Failed":0},"status":200,"statusText":"OK"}; 
var failed = obj.responseJSON.Failed; 
var success = obj.responseJSON.Success; 
+0

謝謝,錯過了.responseJSON部分 – user2542809

0
var json_data = '{"readyState":4,"responseText":"{\"Success\":0,\"Failed\":0}", 
"responseJSON":{"Success":0,"Failed":0},"status":200,"statusText":"OK"}'; 

var obj = JSON.parse(json_data); 


alert(obj.responseJSON.Success); // for success that in responseJSON 
alert(obj.responseJSON.Failed); 

謝謝:)