Sencha Touch Json得到字符串的响应?

时间:2014-01-08 12:05:34

标签: sencha-touch

我正在研究sencha touch。我用它样本json url。我得到了一个成功的结果,但我没有得到字符串的响应值。

我在这里使用代码:

Ext.data.JsonP.request({
       url : 'http://webapps.figleaf.com/arch101/dataservices/mobile/beer.cfc?method=getExcuses',
   method: 'GET',
    params: {
        },
    success: function(response) {
        // this will give you the JSON       
        Ext.Msg.alert('Success', response.responseText); 

    },
    failure: function(response) {         
     Ext.Msg.alert('Error', 'Please try again.', response.responseText);
}
});

我想得到以下回复

foo([
    {"EXCUSE":"I accidentally flushed my wallet down the toilet."},
    {"EXCUSE":"I ran out of water."},
    {"EXCUSE":"The Jets lost again"},
    {"EXCUSE":"I'm on a mission from God"},
    {"EXCUSE":"It was only one sheep..."},
    {"EXCUSE":"I think that I left my smartphone at your place"},
    {"EXCUSE":"My plants are all dying. I think they crave beer."},
    {"EXCUSE":"I need to listen to your Tito Puente albums."},
    {"EXCUSE":"I just found out that Darth Vader is Luke's father."},
    {"EXCUSE":"Sorry, I accidentally butt-dialed you. But since you have time to answer the phone, mind if I come over for a bit?"},
    {"EXCUSE":"I ran out of bacon and the stores are all out!"},
    {"EXCUSE":"Someone stole the cork from my lunch."},
    {"EXCUSE":"My girlfriend is preggers."},
    {"EXCUSE":"My girlfriend is preggers"},
    {"EXCUSE":"Yeast! If I don't get yeast within 30 minutes Ill suffer a brain aneurism."},
    {"EXCUSE":"I heard you had beer. Mind if I come over? I'm on my way over now, assuming you'll say yes. Thanks in advance!"},
    {"EXCUSE":"I heard you had beer. Mind if I come over? I'm on my way over now, assuming you'll say yes. Thanks in advance!"},
    {"EXCUSE":"You said tonight was our Battlestar Galactica marathon...?"},
    {"EXCUSE":"My parents are coming over."},
    {"EXCUSE":"I have plenty of bacon...but no beer. Can I come over?"},
    {"EXCUSE":"I left my iPhone 5 charger at my brothers and I don't have enough time to wait at the Apple store to get a new one."}
]) 

2 个答案:

答案 0 :(得分:1)

这对我有用:

Ext.data.JsonP.request({
    url: 'http://webapps.figleaf.com/arch101/dataservices/mobile/beer.cfc?method=getExcuses',
    method: 'get',

    success: function(response) {
        Ext.each(response, function(excuse) {
            console.log(excuse.EXCUSE);
        });
    },

    failure: function(response) {
        Ext.Msg.alert('Error', 'Please try again.', response.responseText);
    }
});

答案 1 :(得分:0)

好用这个:

success: function(response) {
    // this will give you the JSON       
    Ext.Msg.alert('Success', response[0].EXCUSE); 
},

响应将是数组本身。