com.reandroid.json.JsonUtil Maven / Gradle / Ivy
/*
* Copyright (c) 2002 JSON.org (now "Public Domain")
* This is NOT property of REAndroid
* This package is renamed from org.json.* to avoid class conflict when used on anroid platforms
*/
package com.reandroid.json;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class JsonUtil {
public static void readJSONObject(File file, JSONConvert jsonConvert) throws IOException {
FileInputStream inputStream=new FileInputStream(file);
readJSONObject(inputStream, jsonConvert);
inputStream.close();
}
public static void readJSONObject(InputStream inputStream, JSONConvert jsonConvert){
InputStreamReader reader=new InputStreamReader(inputStream, StandardCharsets.UTF_8);
readJSONObject(reader, jsonConvert);
}
public static void readJSONObject(Reader reader, JSONConvert jsonConvert){
JSONObject jsonObject=new JSONObject(new JSONTokener(reader));
jsonConvert.fromJson(jsonObject);
}
public static void readJSONArray(File file, JSONConvert jsonConvert) throws IOException {
FileInputStream inputStream=new FileInputStream(file);
readJSONArray(inputStream, jsonConvert);
inputStream.close();
}
public static void readJSONArray(InputStream inputStream, JSONConvert jsonConvert){
InputStreamReader reader=new InputStreamReader(inputStream, StandardCharsets.UTF_8);
readJSONArray(reader, jsonConvert);
}
public static void readJSONArray(Reader reader, JSONConvert jsonConvert){
JSONArray jsonObject=new JSONArray(new JSONTokener(reader));
jsonConvert.fromJson(jsonObject);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy