-1

I've finished my application, and when it finishes there will be two json files. I need to combine them in a different java class so i've tried something like this

If i try to use this code

File dirSrc = new File(mydir);


        File[] list = dirSrc.listFiles();
        JSONArray jsonList = new JSONArray();   
        for (File file : list) {
              try {
                jsonList.put(new JSONObject(readFile(file)));
            } catch (JSONException e) {



                e.printStackTrace();
            }
            }

        System.out.println(jsonList);




                private String readFile(File file) {
                String finalOutput = null;
                 try { 
        BufferedReader in = new BufferedReader(new FileReader(file));
        String str;
        while ((str = in.readLine()) != null) {
            finalOutput = str;
        }
        in.close();
    } catch (IOException e) {
    }
    return finalOutput;

}

i get a org.json.JSONException: Value +k�V��䱐*ʜ� of type java.lang.String cannot be converted to JSONObject. Anyone knows what's up?

RayCharles
  • 19
  • 2
  • 8

1 Answers1

0
for (File file : list) {
  jsonList.put(new JSONObject(readFile(file));
}

String readFile(File file) {
....
}
Max
  • 2,917
  • 1
  • 16
  • 16