我将json反序列化为ArrayList
时出现此错误12-31 05:29:10.963: W/System.err(2939): org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_TRUE token
这里是json的结构:
{
"c_Evenement" : [{
"id" : {
"o_id" : 9,
"t_id" : 1,
"key" : "1_9"
},
"bla1" : "bla bla bla bla",
"bla2" : "bla bla bla bla",
"bla3" : "bla bla bla bla",
"bla4" : "bla bla bla bla"
}
],
"themes" : [{
"id" : 1,
"nom" : "Administration"
}
],
"c_Theme" : [{
"id" : {
"couche_id" : 761,
"theme_id" : 1,
"key" : "1_761"
},
"layerId" : 0
}
],
"message" : null,
"ok" : true
}
这里是LireTheme课程:
@JsonIgnoreProperties(ignoreUnknown=true)
public class LireTheme {
private Themes themes;
private CouchesTheme c_Theme;
private ClassesEvenement c_Evenement;
private String message;
private boolean ok;
//getters and setters
}
这里的LireTheme类只是一个映射HashMap:
public class LireThemes extends HashMap<String, ArrayList<LireTheme>> {
private static final long serialVersionUID = 1L;
}
以及我如何反序化它:
LireThemes lirethemes = null;
ArrayList<LireTheme> themeList = null;
final InputStream stream = context.getAssets().open("lireThemes.json");
lirethemes = objectMapper.readValue(stream, LireThemes.class);
themeList = lirethemes.get("themes");
我真的需要帮助。
答案 0 :(得分:2)
是的,现在我可以看到这些属性中的每一个都是集合,而不是简单的属性。因此,对于每一个,杰克逊都试图映射到列表,例如。 所以,试试:
@JsonIgnoreProperties(ignoreUnknown=true)
public class LireTheme {
private List<Themes> themes;
private List<CouchesTheme> c_Theme;
private List<ClassesEvenement> c_Evenement;
private String message;
private boolean ok;
//getters and setters
}
希望这有帮助!