Sencha touch Sencha Touch无法解码并加载数据模型的JSON响应

Sencha touch Sencha Touch无法解码并加载数据模型的JSON响应,sencha-touch,extjs,Sencha Touch,Extjs,我为sencha touch中的一个问题感到非常痛苦,因为它导致服务器响应。我有一个需要与服务器通信的应用程序,服务器将与数据库交互,并以JSON的形式提供信息。 现在,我的问题陈述是成功登录到应用程序,应用程序需要加载模型。模型使用代理下载JSON并在屏幕UI上呈现。问题从这里开始 我使用Servlet获取JSON服务。例如,我硬编码了json。查找下面的Servlet代码 import java.io.IOException; import javax.servlet.ServletExce

我为sencha touch中的一个问题感到非常痛苦,因为它导致服务器响应。我有一个需要与服务器通信的应用程序,服务器将与数据库交互,并以JSON的形式提供信息。 现在,我的问题陈述是成功登录到应用程序,应用程序需要加载模型。模型使用代理下载JSON并在屏幕UI上呈现。问题从这里开始

我使用Servlet获取JSON服务。例如,我硬编码了json。查找下面的Servlet代码

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginJSONServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;       

    public LoginJSONServlet() {
        super();       
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {       
        try {
            response.setContentType("application/json");                        
            String jsonText = "[{\"quoteName\":\"Home care\",\"timeStamp\":\"May2011\"}]";                  
            response.getWriter().write(jsonText);

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
部署后,它将在浏览器中打印所需的JSON作为{“quoteName”:“家庭护理”,“时间戳”:“2011年5月”}

现在,这是我的客户端sencha触摸代码

这是我的商店

App.stores.SavedStore = new Ext.data.JsonStore({
    model: 'SavedModel',
    autoLoad: true
});
这是我的模型

App.models.SavedQuoteMod = Ext.regModel('SavedQuoteMod', {
   fields: [
       {name:'quoteName' , type: 'string' },
       {name:'timeStamp' , type: 'string' }
   ],


   proxy:{
          type: 'ajax',
          format: 'sencha',
          url: 'http://localhost:8091/Sencha/LoginServlet',
          reader: {
               type: 'json',
               root: 'data'
          },


  /* proxy:{
    type: 'ajax',
    url: 'http://172.16.30.18:8091/Sencha/JSONServlet',
    reader: {type:'json'},
    writer: {type:'json'},
   }*/                       
});
我完全不知道我必须使用Ajax、JSONP或任何其他代理请求类型。
我的代码不起作用。请帮帮我

问题出在读者身上。如果指定根:'data',它将需要一个json,看起来像:data:[{“quoteName”:“Home care”,“timeStamp”:“May2011”},… 所以只要删除根:'data'行,它就应该可以工作了

编辑存储区是应该定义代理的存储区

App.stores.SavedStore = new Ext.data.JsonStore({
    model: 'SavedQuoteMod',
    autoLoad: true,
    proxy:{
          type: 'ajax',
          format: 'sencha',
          url: 'http://172.16.30.18:8091/Sencha/subhash.json',
          reader: {
               type: 'json',
          },

});

App.models.SavedQuoteMod = Ext.regModel('SavedQuoteMod', {
   fields: [
       {name:'quoteName' , type: 'string' },
       {name:'timeStamp' , type: 'string' }
   ]
});

按照这种方式配置,存储需要一个json,其中包含元组数组,如[{“quoteName”:“Home care”,“timeStamp”:“May2011”},这实际上就是您发送的内容,如果您为代理设置配置根,则它希望存储的数据位于类似数据的属性中:[{..

@nscrob…我无法正确理解它。请您再解释一下好吗?@nscrob..现在浏览器抛出了未捕获的错误:您使用的是服务器代理,但没有提供url。我相信您使用的是extjs 4,所以存储应该是Ext.data.store,而不是JsonStore