Struts2回来XML,JSON格式

Struts2返回XML,JSON格式2.Action里面的方法import net.sf.json.JSONArrayimport net.sf.json.JSONObject

Struts2返回XML,JSON格式



2.Action里面的方法
import net.sf.json.JSONArray;import net.sf.json.JSONObject;........./** * 通过bean生成JSON数据 * @param bean bean对象 * @return 生成的JSON数据*/public static String getJsonFromBean(Object bean){ try{      JSONObject JsonObject = JSONObject.fromObject(bean);      return JsonObject.toString(); }catch(Exception e){   e.printStackTrace(); } return null;}