/**
* List Conversion JSON format passes JSON data stream to front end
* @param list
* @param response
* @throws IOException
*/
public void Writejson (List list,httpservletresponse response) throws ioexception{
Jsonarray jarray=jsonarray.fromobject (list);
Response.setheader ("Content-type", "text/json;charset=utf-8");
Response.setcharacterencoding ("UTF-8");
Response.getwriter (). Write (jarray.tostring ());
}
/**
*
* Return a field with {Key,value} to a JSON-formatted string returns the Ajax callback function
* @param key
* @param Object
* @param response
* @throws IOException
*/
public void ToJson (String key,object Object, httpservletresponse response) throws ioexception{
Jsonobject obj=new jsonobject ();
Obj.put (Key, object);
Response.setheader ("Content-type", "text/json;charset=utf-8");
Response.setcharacterencoding ("UTF-8");
Response.getwriter (). Write (obj.tostring ());
}
/**
*
* Normal type of Bean converted to JSON format string returns AJAX callback function
* @param Object
* @param response
* @throws IOException
*/
public void ToJson (Object object, HttpServletResponse response) throws ioexception{
Jsonobject Obj=jsonobject.fromobject (object);
Response.setheader ("Content-type", "text/json;charset=utf-8");
Response.setcharacterencoding ("UTF-8");
Response.getwriter (). Write (obj.tostring ());
}
////////////////////////////////////////
Usage (calling function, putting object into function): Writejson (items, response);
The definition of the transfer function of a JSON object