无法访问Ajax JSON数据对象

pm1*_*m13 2 ajax json extjs

我有一个从Ajax调用返回的JSON响应,但似乎根本无法访问JSON的任何部分.

JSON格式为:[{"id":"1","description":"Employee","coverage":"Center","covered":"X"}]

我尝试了以下,没有任何作用:

success: function(result, request){
    jsonData = Ext.util.JSON.decode(result.responseText);
    var id = jsonData.id;
    alert(id);
 }

 * returns as undefined

success: function(result,request){
    jsonData = result.responseText  ##shows the Json perfectly
    alert(jsonData.length) ### displays as number of chars, not how many objects in json string
}
Run Code Online (Sandbox Code Playgroud)

Sak*_*tel 5

Ext.util.JSON.decode是ExtJS3方法,Ext.JSON.decode并且在ExtJS4中,因为你没有指出你正在使用哪个版本的ExtJS,因此将使用Ext.decode在ExtJS3和ExtJS4中都可用的故障保护方式

success: function(result, request){
    jsonData = Ext.decode(result.responseText);
    console.log(jsonData);
}
Run Code Online (Sandbox Code Playgroud)