package test;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.opensymphony.xwork2.ActionSupport;
public class ActionClass extends ActionSupport {
private static final long serialVersionUID = 1L;
private String jsonStr; //私有化字段
//生成set()和get()方法
public String getJsonStr() {
return jsonStr;
}
public void setJsonStr(String jsonStr) {
this.jsonStr = jsonStr;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public String add() {//实现方法
JSONArray tempJsonArry = new JSONArray(); //创建实例化JSONArray对象
JSONObject obj = new JSONObject(); //实例化JSONObject对象
try {
obj.put("name", "啦啦啦"); //键值对
} catch (JSONException e) {
e.printStackTrace();
}
tempJsonArry.put(obj);
jsonStr = tempJsonArry.toString();//转成字符串
return "success";
}
}
pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ taglib prefix="s" uri="/struts-tags" %>
网友评论