BeanA bean2 = (BeanA) JSONObject.toBean(jsonObject2, BeanA.class);
System.out.println(bean2);
// BeanA{bool=true, integer=1, string=json}
}
public class BeanA {
private boolean bool;
private Integer integer;
private String string;
public boolean isBool() {
return bool;
}
public void setBool(boolean bool) {
this.bool = bool;
}
public Integer getInteger() {
return integer;
}
public void setInteger(Integer integer) {
this.integer = integer;
}
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
public String toString() {
return "BeanA{"bool=" + bool +", integer=" + integer +", string=" + string + +"}";
}
}
4.JSON串-->XML
public static void test4() {
System.out.println("------------JSON串-->XML----------");
JSONObject json = new JSONObject(true);
String xml = new XMLSerializer()。write(json);
System.out.println(xml);
JSONObject json1 = JSONObject.fromObject("{"name":"json","bool":true,"int":1}");
String xml1 = new XMLSerializer()。write(json1);
System.out.println(xml1);
JSONArray json2 = JSONArray.fromObject("[1,2,3]");
String xml2 = new XMLSerializer()。write(json2);
System.out.println(xml2);
}
5.XML-->JSON串
public static void test5() {
System.out.println("------------XML-->JSON串----------");
String xml = "" +
" " +
"
" return matrix[i][j]; " +
"