我想學習如何使用傑克遜解析器,以獲得更有效的解析json數據。我有這些jar文件: Downloaded from this pageJacksonParser數據綁定和核心原因「找到APK的重複文件」?
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文件。我不知道該怎麼做......有什麼我做錯了嗎?或者我缺少一些東西?
在此先感謝,任何幫助表示讚賞。
1.9.12:核心LGPL,映射器,LGPL這些罐子的工作,謝謝。 – yahya 2013-04-25 07:48:24
我建議不要使用1.x版本。但是請嘗試2.1.4 - 它是2.x兼容的。 – StaxMan 2013-04-26 17:07:10
哪裏可以找到2.1.x版本的下載?我只在他們的網站上看到2.2和1.x的東西。 – 2013-05-03 03:27:04