开发者

How to merge two json files together in java

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?


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

String readFile(File file) {
....
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜