Convert InputStream to JSONObject

前端 未结 13 1885
刺人心
刺人心 2020-12-05 03:52

I am converting InputStream to JSONObject using following code. My question is, is there any simple way to convert InputStream to JSONObject. Without doing InputStream -> Bu

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 04:33

    Here is a solution that doesn't use a loop and uses the Android API only:

    InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName);
    byte[] data = new byte[inputStreamObject.available()];
    if(inputStreamObject.read(data) == data.length) {
        JSONObject jsonObject = new JSONObject(new String(data));
    }
    

提交回复
热议问题