我正在尝试学习如何使用jackson解析器,以便更有效地解析json数据.我有这些jar文件:
Downloaded from this page
Downloaded from this page
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文件有一些共同点.我不知道该怎么做……有什么我做错了吗?或者我做了一些缺失的事情
在此先感谢,任何帮助表示赞赏.
解决方法
我也有同样的问题.
所以,我使用旧版本.
所以,我使用旧版本.
jackson-core-asl-1.9.12.jar
jackson-mapper-asl-1.9.12.jar
您可以从同一页面的“Latest stable 1.x version”下载.