//引入相应的包
//json-lib-2.2-jdk15.jar
importnet.sf.json.JSONArray;
importnet.sf.json.JSONObject;
1.//把java对象列表转换为json对象数组,并转为字符串
JSONArrayarray=JSONArray.fromObject(userlist);
Stringjsonstr=array.toString();
2.//把java对象转换成json对象,并转化为字符串
JSONObjectobject=JSONObject.fromObject(invite);
3.//把JSON字符串转换为JAVA对象数组
Stringpersonstr=getRequest().getParameter("persons");
JSONArrayjson=JSONArray.fromObject(personstr);
List<InvoidPerson>persons=(List<InvoidPerson>)JSONArray.toCollection(json,nvoidPerson.class);