Simplest way to read json from a URL in java

后端 未结 11 1097
情书的邮戳
情书的邮戳 2020-11-22 04:15

This might be a dumb question but what is the simplest way to read and parse JSON from URL in Java?

In Groovy, it\

11条回答
  •  梦如初夏
    2020-11-22 05:14

    If you don't mind using a couple libraries it can be done in a single line.

    Include Apache Commons IOUtils & json.org libraries.

    JSONObject json = new JSONObject(IOUtils.toString(new URL("https://graph.facebook.com/me"), Charset.forName("UTF-8")));
    

提交回复
热议问题