将 InputStream 转换为 JSONObject
2022-08-31 20:17:05
我正在使用以下代码将 InputStream 转换为 JSONObject。我的问题是,有没有简单的方法将 InputStream 转换为 JSONObject。无需执行 InputStream -> BufferedReader -> StringBuilder -> 循环 -> JSONObject.toString()。
InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName);
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStreamObject, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
JSONObject jsonObject = new JSONObject(responseStrBuilder.toString());