【问题标题】:Sench Touch Json get response to string?Sench Touch Json 得到对字符串的响应?
【发布时间】:2014-01-08 12:05:33
【问题描述】:

我正在研究煎茶触摸。我使用它示例 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."}
]) 

【问题讨论】:

  • 对不起,我不是很清楚。您是否在响应中将此数组作为字符串?
  • 嗨,benda。我想获得公正的价值。
  • Benda 我只想显示响应值。之后我实现数组并获取详细信息。但我无法获得响应值
  • 那么响应的内容是什么?
  • 嗨 Nicolas Grunfeld 请看这个链接webapps.figleaf.com/arch101/dataservices/mobile/…

标签: sencha-touch


【解决方案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);
    }
});

【讨论】:

    【解决方案2】:

    好的,用这个:

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

    响应将是数组本身。

    【讨论】:

    • +100 感谢 benka。非常感谢我得到了答复
    • 嗨,本卡,如果我想获得所有价值意味着我将它用于(int i = 0;i
    • 你可以做for (resp in response) { Ext.Msg.alert('Success', response[resp].EXCUSE); }这将遍历所有元素
    • benka 我只得到了最后一个值。给我任何解决方案
    • 你明白了,但每个警报弹出窗口都会覆盖前一个,所以你只会看到最后一个。您不想显示与您拥有的 EXCUSE 项目一样多的弹出警报消息,是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    相关资源
    最近更新 更多