日期:2014-05-19 浏览次数:20683 次
{"method":"login.doLogin","params":["username","password","location"]}
public class LoginBean{
private String method;
private String username;
private String password;
private String location;
// getter and setter methods
}
[["ID","USERNAME","PASSWORD"],["DATA_ID","DATA_USERNAME","DATA_PASSWORD"]]
public class UserInfo{
private String id;
private String username;
private String password;
//getter and setter methods
}
public class JsonToJavaBean {
public static void main(String[] args) {
String str="{\"student\":[{\"name\":\"leilei\",\"age\":23,\"gender\":true},{\"name\":\"leilei02\",\"age\":23,\"gender\":false}]}";
Student stu = null;
List<Student> list = null;
try {
ObjectMapper objectMapper=new ObjectMapper();
StudentList studentList=objectMapper.readValue(str, StudentList.class);
list=studentList.getStudent();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(Student s:list){
System.out.println(s.getName()+" "+s.getAge()+" "+s.isGender());
}
}
}
public class JavaBeanToJson {
public static void main(String[] args) {