Reputation: 6719
My Sencha Touch mobile app hits a web service and gets a JSON reponse, I just can't figure out what to DO with it.
Here's my code:
var declineResult = new Ext.regStore('declineResult',
{
model: 'BaseResponse',
proxy : {
type : 'ajax',
dataType: "json",
url : App.BaseURL + '/SetJobResponse/' + options.jobId + '/' + STCID +'/1/' + device.uuid,
reader: new Ext.data.JsonReader ({
type: 'json'
})
},
listeners:
{
load: function(Field1, Field2, Field3, Field4)
{
var myDate = new Date(Field4);
alert('response message:' + Field1 + ',' + Field2 + ',' + Field3 + ',' + Field4 + ',' + myDate.getDate());
}
}
});
Ext.StoreMgr.get("declineResult").load();
Browsing to the URL gives:
{"ErrorMessage":"You are not authorised","ResponseTime":"\/Date(1321447985287)\/","StatusCode":401,"Success":false}
But no matter what I do, I can't get anything meaningful to come up in the alert(). I've tried converting to various data types, JSON parsing, getValue() and new String(Field1) and every similar function under the sun. all I get is [object Object] or NaN. I can't even be sure which field is which.
Every example on the internet seems to assume you're just plugging it into a grid or something. How do I interrogate these fields?
Upvotes: 0
Views: 166
Reputation: 6719
The load event had a different signature:
'load': function(store,records,successful)
Upvotes: 0
Reputation: 2627
I do not know Sencha and cannot work out how your app is getting any response at all but obviously it is, so if your alert gives you [object Object] try:
alert (Field1.ErrorMessage);
If that does not work try:
var res = JSON.parse(Field1);
alert (res.ErrorMessage);
If you do not get anything sensible from either of those then checking that you are getting some sort of response (and it is in the format you are expecting) using Web Inspector (Safari), Firebug (Firefox) or a similar debugging tool would be further avenue to explore.
Upvotes: 0
Reputation: 719
Steve,
The data must be in the format "{'.....':'.....','.....':'.....',....}" in pairs, separated by colons and, the entire set, between brackets. Then you can parseJSON.
Good luck. More info could help us help you!
Upvotes: 1