将json字符串转换为Java数组
隐私保护JSON=' {' address' :' chian', ' birthday' : {' birthday' 3360 } birthday}
@Test
公共void read JSON 2阵列(
try {
json='[' json '];
JSON array=JSON array.from object (JSON );
Object[] os=jsonArray.toArray (;
Student[] stus=(Student[] ) JSONArray.toArray(JSONArray,Student.class );
}catch(exceptione ) {
e .打印堆栈跟踪(;
}
}
执行结果如下
=========jsonarrystringjavaarray====================
#%%%{'address':'chian ',' birthday ' : { ' birthday ' : ' 2010-11-22 ' },' email'3360'email}
1
{'address':'chian ',' birthday ' : { ' birthday ' : ' 2010-11-22 ' },' email':'email@123.} .
{'address':'chian ',' birthday ' : { ' birthday ' : ' 2010-11-22 ' },' email':'email@123.} .
1
将JSON字符串转换为Java的列表集合
隐私保护JSON=' {' address' :' chian', ' birthday' : {' birthday' 3360 } birthday}
公共void read JSON2list (
try {
json='[' json '];
JSON array=JSON array.from object (JSON );
列表列表=JSON array.to list (JSON array,Student.class );
list=JSON array.to list (JSON array;
}catch(exceptione ) {
e .打印堆栈跟踪(;
}
}