2014-01-08 51 views
2

我正在使用sencha touch。我用它示例json url。我得到了一個成功的結果,但我沒有得到字符串的響應值。Sench Touch Json獲取字符串響應?

我在這裏使用代碼:

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."} 
]) 
+0

對不起,我並不完全清楚。你是否在響應中將這個數組作爲字符串? – benka

+0

嗨benda.i想獲得價值。 – Gomathi

+0

本達我只想顯示響應值。之後,我實現了數組並獲取詳細信息。但是我無法獲得響應值 – Gomathi

回答

0

好使用這樣的:

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

響應是數組本身。

+0

+100謝謝你benka.Thank你非常我得到了答案 – Gomathi

+0

嗨benka如果我想得到所有的價值意味着我用它(INT我= 0;我 Gomathi

+1

你可以做'for(resp in response){ Ext.Msg.alert('Success',response [resp] .EXCUSE) ; }' 這將遍歷所有元素 – benka

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); 
    } 
});