Get JSON Data from URL Using Android?

后端 未结 8 2060
长发绾君心
长发绾君心 2020-11-28 04:48

I am trying to get JSON data by parsing login url with username and password. I have tried by using below code but I can\'t get any responses. Please help me.

I am u

8条回答
  •  [愿得一人]
    2020-11-28 05:24

    Don't know about android but in POJ I use

    public final class MyJSONObject extends JSONObject {
        public MyJSONObject(URL url) throws IOException {
            super(getServerData(url));
        }
        static String getServerData(URL url) throws IOException {
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            BufferedReader ir = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String text = ir.lines().collect(Collectors.joining("\n"));
            return (text);
        }
    }
    

提交回复
热议问题