我是煎茶触摸的新手。我需要通过使用 RESTful 架构来传递 json 数据。但我不知道如何启动它。有人能给我举个例子吗?顺便说一句,我正在使用 JACKSON 库。
这是我的 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;
}
}
如何将结果显示到我的煎茶触摸项目?通过使用列表或面板?