How can I get a Javascript variable value in Java?

前端 未结 2 379
迷失自我
迷失自我 2021-01-19 04:47

In my current project I have to read a JavaScript file from the web and extract an object from it. The variable can vary from time to time, so I have to read it instead of h

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 05:50

    There are many libraries in Java to parse the JSON. There is a list on JSON.org

    Read the file with Java

    import org.json.JSONObject;
    
    URL url = new URL("http://example.com/foo.js");
    InputStream urlInputStream = url.openStream();
    JSONObject json = new JSONObject(urlInputStream.toString());  
    

提交回复
热议问题