如何将Json数组字符串转化为Json的List
1个回答
展开全部
将json字符串转成Java的Array数组
private String json = "{\"address\":\"chian\",\"birthday\"消拍:{\"birthday\":\"2010-11-22\拿祥羡"},"+
"\"email\":\"宴李email@123.com\",\"id\":22,\"name\":\"tom\"}";
@Test
public void readJSON2Array() {
try {
json = "[" + json + "]";
jsonArray = JSONArray.fromObject(json);
Object[] os = jsonArray.toArray();
System.out.println(os.length);
Student[] stus = (Student[]) JSONArray.toArray(jsonArray, Student.class);
System.out.println(stus.length);
System.out.println(stus[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
private String json = "{\"address\":\"chian\",\"birthday\"消拍:{\"birthday\":\"2010-11-22\拿祥羡"},"+
"\"email\":\"宴李email@123.com\",\"id\":22,\"name\":\"tom\"}";
@Test
public void readJSON2Array() {
try {
json = "[" + json + "]";
jsonArray = JSONArray.fromObject(json);
Object[] os = jsonArray.toArray();
System.out.println(os.length);
Student[] stus = (Student[]) JSONArray.toArray(jsonArray, Student.class);
System.out.println(stus.length);
System.out.println(stus[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询