Android:本地json文件解析

/**
 * 获取json文件字符串
 * @param fileName
 * @param context
 * @return
 */
public static String getJson(String fileName, Context context) {
    StringBuilder stringBuilder = new StringBuilder();
    try {
        File file = new File(fileName);
        FileInputStream is = new FileInputStream(file);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return stringBuilder.toString();
}

 

你可能感兴趣的:(android)