// 将request中的json字符串转换为json对象
JSONObject jsonObject = null;
String inputLine = null;
StringBuffer josnData = new StringBuffer();
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
System.out.println("====>"+in);
while ((inputLine = in.readLine()) != null) {
josnData.append(inputLine);
}
jsonObject = JSONObject.fromObject(josnData.toString());
} catch (IOException e) {
e.printStackTrace();
}
return jsonObject;
}
根据json对象得到对应key的值:
String value=jsonObject.getString(key);