0

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?

0

3 Answers 3

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but what more info do you need? I've given you the code and the JSON sent back by the server, I just need to know how to get it from [object Object] to "You are not authorised" etc..
Hi Steve, maybe I put my tongue where I shouldn't have: sencha (I don't even know what that is). However, my intention was to alert you to check the format of the data returned. Once again: good luck!
0

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.

Comments

0

The load event had a different signature:

'load': function(store,records,successful)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.