1、通过InputStream得到BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
或者
Reader reader = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(reader);
或者
InputStream inputStream;
InputStreamReader r = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(r);
2、通过InputStream得到JSONObject
JSONObject jsonObject = new JSONObject(new JSONTokener(inputStream));
或者
JsonElement element = new JsonParser().parse(new InputStreamReader(inputStream));
JSONObject jsonObject = new JSONObject(element.getAsJsonObject().toString());
或者
BufferedReader bR = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
StringBuilder responseStrBuilder = new StringBuilder();
while((line = bR.readLine()) != null){
responseStrBuilder.append(line);
}
inputStream.close();
JSONObject result= new JSONObject(responseStrBuilder.toString());
相关文档:
Java 复制克隆(clone)Inputstream的方法及示例代码
Java Inputstream流转换读取成byte[]字节数组方法及示例代码
Java Inputstream流转换读取成String字符串方法及示例代码