json データをより効果的に解析するために、jackson パーサーの使用方法を学ぼうとしています。私はこれらの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
Google でこのエラーを検索すると、これらの jar ファイルに共通するクラスがあると表示されます。そして、私は何をすべきかについて何も考えていません...私が間違っていることはありますか? または、何か足りないことをしますか?
事前に感謝します。どんな助けでも大歓迎です。