json字符串和java对象的互相转换

//把java对象存为json对象数组

JSONArray json = JSONArray.fromObject(list);

//把java对象存为json对象

JSONObject json1= JSONObject.fromObject(list);


//json字符串转为json数组
JSONArray json = JSONArray.fromObject(personstr);
List<InvoidPerson> persons = (List<InvoidPerson>)JSONArray.toCollection(json, nvoidPerson.class);

//json字符串转为json对象
JSONObject jsonobject = JSONObject.fromObject(str);
passportlends = (PassportLendsEntity)JSONObject.toBean(jsonobject, PassportLendsEntity.class);

 

你可能感兴趣的:(java对象,json字符串)