yah*_*hya 7 android json jar jackson
我正在尝试学习如何使用jackson解析器,以便更有效地解析json数据.我有这些jar文件: 从这个页面下载
jackson-core-2.2.0.jar
jackson-annotations-2.2.0.jar
jackson-databind-2.2.0.jar
Run Code Online (Sandbox Code Playgroud)
在代码中,我只是尝试将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));
}
Run Code Online (Sandbox Code Playgroud)
不确定是否有必要,但这里也是我的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;
}
}
Run Code Online (Sandbox Code Playgroud)
一切似乎都没问题,没有错误或警告.但是当我尝试编译时,它会给出这个错误:
[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
Run Code Online (Sandbox Code Playgroud)
当我在谷歌上搜索这个错误时,它说这些jar文件有一些共同点.我不知道该怎么做......有什么我做错了吗?或者我做了一些缺失的事情
在此先感谢,任何帮助表示赞赏.
小智 2
我也有同样的问题。所以,我使用旧版本。
jackson-core-asl-1.9.12.jar
杰克逊-mapper-asl-1.9.12.jar
您可以从同一页面的“最新稳定 1.x 版本”下载。