Sencha touch XML对JSON的响应 [英] Sencha touch XML response to JSON

查看:91
本文介绍了Sencha touch XML对JSON的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Sencha touch中启动了一个使用现有Web服务的项目. 作为这项技术的新手,我在完成某些功能时面临某些问题.

I have recently started a project in Sencha touch with existing Web-services. Being very new to the technology, I am facing certain issues in accomplishing some functionality.

问题 我必须致电登录服务,请求如下:

Problem I have to call login service and the request goes like:

http://domain.sub.com/Service.asmx/LoginService?body={"Username":"maj@smaj.com","Password":"p12345","Token":122112321123212123,"Method":"Login","LabId":"(null)","Hash":"fr3f33f3334348u8yy8hfuhdu8bdy7y89u89x8998c89789c87d78r9","DeviceType":"iPhone Simulator","DeviceId":"91BF3299-A94C-5AD3-9C35-A5C9BBBB6AA8","ApplicationType":"iPhone","Id":"998390494"}

,但是响应以XML格式出现: 响应:

but the response is coming in XML format as: RESPONSE:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://domain2.sub2.com/MobileWebService/">{"Id":"null","Message":"Logged In.","Status":true,"LoggedIn":true}</string>

我必须将此xml解析为json才能从响应中获取{"Id":"null","Message":"Logged In.","Status":true,"LoggedIn":true}.

I have to parse this xml to json to get : {"Id":"null","Message":"Logged In.","Status":true,"LoggedIn":true} out of the response.

然后使用状态,登录名和ID来验证登录名.

then use the Status, LoggedIn and Id to verify the login.

我的想法 我不确定它是否正确,我正在尝试创建两个商店xmlStore和JsonStore.

My Idea I am not sure whether its right, I am trying to create two stores, xmlStore and JsonStore.

??

  • 如何将xml响应存储在字符串中.
  • 我如何将这个字符串传递给Json Store(在url的位置?)

我听起来可能很天真,但这是我的问题;)

I may sound very naive to this, but this is my problem ;)

请指导.

我意识到自己正在跨网域请求. 是造成问题或混乱的原因.假设我没有跨域请求,该如何处理?

I realized tha I am diving cross domain request. is that what is causing problems or confusion. How to deal with it suppose I did not had cross domain requests?

推荐答案

如果您要进行跨域请求,请在代理中使用scripttag代替ajax.这是一个json示例

If you are doing cross domain requests use scripttag in your proxy in place of ajax. Here is a json example

例如.

mApp.stores.onlineStore = new Ext.data.Store({
 model: 'XPosts',
 proxy: {
           type: 'scripttag',
           url : 'http://domain.com/data.json',
           reader: new Ext.data.JsonReader({
               root: 'pages'
           }),
            timeout: 3000,
        listeners: {
            exception:function () {
                console.log("onlineStore: failed");
            },
                success: function(){
                    console.log("onlineStore: success");
                }
            }
       },
    autoLoad: true
 });

离线商店:

mApp.stores.offlineStore = new Ext.data.Store({
    model: 'XPosts',
    proxy: {
        type: 'localstorage',
        id: 'appdata',
        reader: new Ext.data.JsonReader({
            root: 'pages'
        })
    },
    autoLoad: true
});

然后,在您的启动中:

this.stores.onlineStore.addListener('load', function () {
       console.log("onlineStore: online");
       mApp.stores.offlineStore.proxy.clear();
        console.log("offlineStore: cleared");
        this.each(function (record) {
            console.log("offlineStore: adding record");
           mApp.stores.offlineStore.add(record.data)[0];
       });
       mApp.stores.offlineStore.sync();
        console.log("offlineStore: synced");
        mApp.stores.offlineStore.load();
    });
    this.stores.onlineStore.load();

可能会有一些错误,因此请提前警告!

May have some bugs so beforewarned!

这篇关于Sencha touch XML对JSON的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆