Gson解析post和put提交的简单数据

使用Map来接收

Gson gson = new Gson();

String json;
try {
    BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"));  
    StringBuffer sb = new StringBuffer("");
    String temp;
    while ((temp = br.readLine()) != null) {
        sb.append(temp);
    }
    br.close();
    json = sb.toString();
    Map result = gson.fromJson(json, new TypeToken>(){}.getType());
    System.out.println(result.get("name"));
    System.out.println(result.get("id"));
} catch (Exception e) {
    e.printStackTrace();
}

你可能感兴趣的:(Gson解析post和put提交的简单数据)