Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将json结果传递给sencha touch_Java_Json_Sencha Touch_Restful Architecture - Fatal编程技术网

Java 将json结果传递给sencha touch

Java 将json结果传递给sencha touch,java,json,sencha-touch,restful-architecture,Java,Json,Sencha Touch,Restful Architecture,我对sencha touch是新手。我需要使用RESTful架构传递json数据。但我不知道如何启动它。有人能给我举个例子吗?顺便说一句,我正在使用杰克逊图书馆 这是我的java文件-jsonTest.java package jsonTest; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.ArrayList; import java.util.List

我对sencha touch是新手。我需要使用RESTful架构传递json数据。但我不知道如何启动它。有人能给我举个例子吗?顺便说一句,我正在使用杰克逊图书馆

这是我的java文件-jsonTest.java

    package jsonTest;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;



import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.sun.xml.internal.bind.api.TypeReference;



public class jsonTest {

      private static List<String> countries;
        private static List<String> tags;

         public static void main(String[] args) {

            String data = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps,"+ 
                    "United Kingdom,United States,Uruguay,Uzbekistan,Vanuatu,Vatican City,Venezuela,Vietnam,Yemen,Zambia,Zimbabwe";

            countries = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(data, ",");

            //Parse the country CSV list and set as Array
            while(st.hasMoreTokens()) {
                countries.add(st.nextToken().trim());
            }

            String strTags = "SharePoint, Spring, Struts, Java, JQuery, ASP, PHP, JavaScript, MySQL, ASP, .NET";
            tags = new ArrayList<String>();
            StringTokenizer st2 = new StringTokenizer(strTags, ",");

            //Parse the tags CSV list and set as Array
            while(st2.hasMoreTokens()) {
                tags.add(st2.nextToken().trim());
            }

        }

        public List<String> getCountryList(String query) {

            String country = null;
            query = query.toLowerCase();
            List<String> matched = new ArrayList<String>();
            for(int i=0; i < countries.size(); i++) {
                country = countries.get(i).toLowerCase();
                if(country.startsWith(query)) {
                    matched.add(countries.get(i));
                }
            }
            return matched;
        }

        public List<String> getTechList(String query) {
            String country = null;
            query = query.toLowerCase();
            List<String> matched = new ArrayList<String>();
            for(int i=0; i < tags.size(); i++) {
                country = tags.get(i).toLowerCase();
                if(country.startsWith(query)) {
                    matched.add(tags.get(i));
                }
            }
            return matched;
        }

}
包jsonTest;
导入java.io.File;
导入java.io.IOException;
导入java.util.Map;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.StringTokenizer;
导入org.codehaus.jackson.jsonecoding;
导入org.codehaus.jackson.json工厂;
导入org.codehaus.jackson.jsongGenerationException;
导入org.codehaus.jackson.jsonggenerator;
导入org.codehaus.jackson.map.JsonMappingException;
导入org.codehaus.jackson.map.ObjectMapper;
导入com.sun.xml.internal.bind.api.TypeReference;
公共类jsonTest{
私有静态列表国家;
私有静态列表标签;
公共静态void main(字符串[]args){
String data=“阿富汗、阿尔巴尼亚、阿尔及利亚、安道尔、安哥拉、安提瓜和Deps,”+
“联合王国、美国、乌拉圭、乌兹别克斯坦、瓦努阿图、梵蒂冈城、委内瑞拉、越南、也门、赞比亚、津巴布韦”;
国家/地区=新阵列列表();
StringTokenizer st=新的StringTokenizer(数据,“,”);
//解析国家/地区CSV列表并设置为数组
而(st.hasMoreTokens()){
添加(st.nextToken().trim());
}
String strTags=“SharePoint、Spring、Struts、Java、JQuery、ASP、PHP、JavaScript、MySQL、ASP、.NET”;
tags=newarraylist();
StringTokenizer st2=新的StringTokenizer(strTags,“,”);
//解析标记CSV列表并设置为数组
while(st2.hasMoreTokens()){
tags.add(st2.nextToken().trim());
}
}
公共列表getCountryList(字符串查询){
字符串country=null;
query=query.toLowerCase();
列表匹配=新的ArrayList();
对于(int i=0;i
如何将结果显示到sencha touch项目中?使用列表或面板?

我建议将其用于开发web服务。具体来说,正如我使用Jersey时所做的那样,它支持POJO映射,即您的web服务可以返回一个POJO(纯旧Java对象),Jersey可以隐式地将其转换为JSON

这里有一个来自mkyong网站的工作示例,用于映射和分析


PS:我没有与sencha Touch合作的经验,因此对此无能为力。

嗨,谢谢你的回答。我试试这个例子。但是我得到了错误HTTP Status 404-/RestfulExample/json/product/get您是否在
web.xml
中输入了适当的条目?您是否使用了下载时提供的全部源代码?此外,您需要在tomcat上部署war?你在这么做吗?是的。我试着用这个例子,你的意思是什么?在tomcat上部署战争?很抱歉,我是javaOk新手,您缺少一些步骤。搜索
在tomcat上部署war
以及
安装tomcat
。Tomcat是一个应用服务器,您需要在该容器上运行web服务。