字节流转换为字符串 // 解析数组json

private String streamToString(InputStream inputStream,String charset) {
        try {
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream,charset);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String s = null;
            StringBuilder builder = new StringBuilder();
            while ((s = bufferedReader.readLine()) != null){
                builder.append(s);
            }
            bufferedReader.close();
            return builder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;

    }


<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=解析数组形式的json=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=->

                //解析
                Gson gson = new Gson();
                Type type = new TypeToken>() {
                }.getType();
                List listData = gson.fromJson(s,type);
                //{}...整个所有数据装在bean对象
                //调用工具类方法
                //DataDataBean dataDataBean = JsonUtil.parseJson(s, DataDataBean.class);
                listAll.addAll(listData.get(0).getData());
                //设置适配器

你可能感兴趣的:(字节流转换为字符串 // 解析数组json)