集合_switch_json

来源:互联网 发布:java数组元素相加 编辑:程序博客网 时间:2024/04/29 18:02
package itHeiMaTestz2;
/*
 * 需要的json转换包:fastjson-1.1.34.android.jar
 * *
 */

import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSONObject;


public class GsonZHU {


public static void main(String[] args) {
List list  = new ArrayList<String>();
String json = JSONObject.toJSONString(list);//将list集合转为json
//发送
/*
 * 就用ServletActionContext获取在struts环境中
 * protected PrintWriter getOut()
{
HttpServletResponse response = ServletActionContext.getResponse();
try {
return response.getWriter();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

然后:
PrintWriter getOut = getOut();
getOut.print(json);//这样通过action就发送前端了
 * */
}


}
0 0
原创粉丝点击