json文件获取String

在raw文件中读取json文件转换为InputStream.

getResources().openRawResource(R.raw.song_sheet_data)

在根据InputStream流转换为字符串的工具类

public static String inputStreamToString(InputStream inputStream) {

try {

byte[] bytes = new byte[inputStream.available()];

inputStream.read(bytes, 0, bytes.length);

String json = new String(bytes);

return json;

} catch (IOException e) {

return null;

}

}

转换简单直接

猜你喜欢

转载自blog.csdn.net/bianjiyuyan/article/details/82586823
今日推荐