我正在尝试学习如何使用杰克逊解析器,以更有效地解析 json 数据。我有这些 jar 文件: 从这个页面下载
jackson-core-2.2.0.jar
jackson-annotations-2.2.0.jar
jackson-databind-2.2.0.jar
在代码中,我只是尝试将 json 解析为对象数组:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String json = ReadFromRaw(this, R.raw.json);
ArrayList<Category> categories = null;
try {
ObjectMapper mapper = new ObjectMapper();
categories = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Category.class));
// categories = mapper.readValue(json, new TypeReference<List<Category>>() {});
} catch (Exception e) {
Log.e("MainActivity", "Error: " + e.getMessage());
}
SimpleListView myList = (SimpleListView) findViewById(R.id.myList);
myList.setAdapterWithItems(GetAdapter(categories));
}
不确定是否有必要,但这里也是我的 Category 类:
@JsonIgnoreProperties({ "DisplayPriority" })
public class Category {
@JsonProperty("Id")
private String categoryId;
@JsonProperty("name")
private String categoryName;
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}
一切似乎都很好,没有错误或警告。但是当我尝试编译时,它给出了这个错误:
[2013-04-25 09:32:08 - Training - JacksonParser] Error generating final archive: Found duplicate file for APK: LICENSE
Origin 1: C:\~\workspace\Training - JacksonParser\libs\jackson-core-2.2.0.jar
Origin 2: C:\~\workspace\Training - JacksonParser\libs\jackson-databind-2.2.0.jar
当我在谷歌上搜索这个错误时,它说这些 jar 文件有一些共同的类。而且我不知道该怎么做......我做错了什么吗?或者我做了一些缺少的事情?
在此先感谢,任何帮助表示赞赏。