//这里将本地String类型的json数据转为json格式保存下载
File file = new File("本地json文件路径,带后缀的具体文件");//创建File文件
if (file.isFile() && file.exists()) { //判定file文件是否存在
//输入流并设定编码
InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
//读取输入的数据
BufferedReader bufferedread = new BufferedReader(read);
//设定两个字符串对象,一个用来读每一个字符流,一个用来存最终的数据
String Txt = "";
String text = "";
while ((Txt = ()) != null) {
Txt = Txt.replace("\n", "");//使用""替换空格
text = text + Txt;
}
//关闭输入流
read.close();
//将字符串对象转为json格式
//如果字符串text是json数组就用前面的,如果是对象就用括号里面的
JSONArray jsonarray = new JSONArray();(JSONObject jsonObject = new JSONObject();)