數據對象的名單我有一個JSON結構看起來像這樣:嵌入式傑克遜
{"data": [{"mykey": "someval"}, {"mykey": "someotherval"}], "foo": "bar"}
我也有
public MyClass {
public String mykey;
}
現在我想反序列化我的JSON的"data"
內容到一個List<MyClass>
使用傑克遜,所以我有這個代碼:
ObjectMapper mapper = new ObjectMapper();
List<MyClass> l = (List<MyClass>) mapper.readerFor(new TypeReference<List<MyClass>>(){}).
withRootName("data").readValue(myJSONString);
但是,這給了我一個e xception:
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (FIELD_NAME),
expected END_OBJECT: Current token not END_OBJECT (to match wrapper object with root name
'data'), but FIELD_NAME
任何人都知道我需要做什麼才能得到這個解析?
你看過http://stackoverflow.com/questions/6349421/how-to-use-jackson-to-deserialise-an-array-of-objects? – ryuu9187
正在創建一個'data'對象而不是一個選項? – Coder
其實,我的JSON還有一個奇怪之處。它還有一些我需要忽略的東西(「foo」:「bar」)。我想我可以添加一個數據對象,但它感覺相當無用 –