我需要将某个JSON字符串转换为Java对象.我正在使用Jackson进行JSON处理.我无法控制输入JSON(我从Web服务中读取).这是我的输入JSON:
{"wrapper":[{"id":"13","name":"Fred"}]}
Run Code Online (Sandbox Code Playgroud)
这是一个简化的用例:
private void tryReading() {
String jsonStr = "{\"wrapper\"\:[{\"id\":\"13\",\"name\":\"Fred\"}]}";
ObjectMapper mapper = new ObjectMapper();
Wrapper wrapper = null;
try {
wrapper = mapper.readValue(jsonStr , Wrapper.class);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("wrapper = " + wrapper);
}
Run Code Online (Sandbox Code Playgroud)
我的实体类是:
public Class Student {
private String name;
private String id;
//getters & setters for name & id here
}
Run Code Online (Sandbox Code Playgroud)
My Wrapper类基本上是一个容器对象,用于获取我的学生列表:
public Class Wrapper {
private List<Student> students;
//getters & setters here
}
Run Code Online (Sandbox Code Playgroud)
我一直收到这个错误,"包装"返回null.我不确定缺少什么.有人可以帮忙吗?
org.codehaus.jackson.map.exc.UnrecognizedPropertyException:
Unrecognized field …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Wicket中的键String和值来添加和获取.List<object>PageParameters
虽然我用钥匙取得价值,但我得到了 classcastException:String cant be converted into list.
我使用的是这样的东西:
List<Example> list = (List<Example>)params.get("ExampleList");
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.