标签:user text public input new throw html string org
使用的是google 的json转换jar
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.IOUtils;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
//输入流的方式获取数据(自能获取一次)
//前端传来的数据为 {"act":1,"userinfo":{"nickname":"耐心"}}
String requestStr = IOUtils.toString(request.getInputStream(), "UTF-8");
JsonParser parser = new JsonParser();
JsonObject root = parser.parse(requestStr).getAsJsonObject();
int act = root.get("act").getAsInt();
JsonObject userinfo = root.get("userinfo").getAsJsonObject();
String Nickname=userinfo.get("nickname").getAsString());
}
标签:user text public input new throw html string org
原文地址:http://www.cnblogs.com/j2ee-web-01/p/6754153.html