Reputation: 745
I have a JSON response returning from an Ajax call but cannot seem to access any part of the JSON at all.
The JSON format is: [{"id":"1","description":"Employee","coverage":"Center","covered":"X"}]
I have tried the following and nothing works:
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
}
Upvotes: 2
Views: 4510
Reputation: 3253
You may use "evil" eval
for this:
var jsonData;
eval('jsonData =' + result.responseText);
alert(jsonData[0].id);
Upvotes: 0
Reputation: 6683
Ext.util.JSON.decode
is ExtJS3 method and Ext.JSON.decode
is in ExtJS4, as you have not indicated which version of ExtJS you are using so failsafe way will be to use Ext.decode
which is available in both ExtJS3 and ExtJS4
success: function(result, request){
jsonData = Ext.decode(result.responseText);
console.log(jsonData);
}
Upvotes: 5