需要一些帮助将java org.json转换为jackson

时间:2018-07-30 04:49:23

标签: java jackson org.json

这里的Newb试图在Java中创建一个插件,我花了很长时间才使它在org.json中工作,并希望有人可以帮助我将其转换为jackson,因为当我遇到内存问题时,使用org.json(下载30mb的文件最终会使用800mb的ram,并且在停止重复下载之前达到并保持在3gb)

任何有关如何减少内存使用的建议也将受到欢迎。 (应用程序在加载时为65mb,下载后达到800mb,在创建json文件时达到1.2gb,然后每次再次下载时增加200-300mb)

public void getAHdata() throws Exception {
    BufferedReader in = null;
    HttpURLConnection con = null;

    try {
        URL obj = new URL(getAHURL());
        con = (HttpURLConnection) obj.openConnection();
        in = new BufferedReader(new InputStreamReader(con.getInputStream()));

        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        JSONObject myResponse = new JSONObject(response.toString());
        JSONArray objarray = myResponse.getJSONArray("auctions"); //it has one other array but I only need auctions: http://auction-api-eu.worldofwarcraft.com/auction-data/54866b3dbf5983e2599b240798cf2938/auctions.json

        try (FileWriter file = new FileWriter("TN.json")) {
            file.write(objarray.toString());
            file.close();
        }
        objarray = null; //dont think this helped with memory
        response = null;
        myResponse = null;
    } catch (MalformedURLException ex) {

    } catch (IOException ex) {

    } 
}

0 个答案:

没有答案