L
L
LSP552020-10-23 10:23:39
Java
LSP55, 2020-10-23 10:23:39

How to get values ​​from HttpsUrlConnection?

Karoch, I'll send a request to YouTube, I get a bunch of lines, how can I get what I need from these lines? Didn't find the answer anywhere, who fumbles?

URL url = new URL(texturl.replace("{id}", args[0]));
      
      HttpsURLConnection connect = (HttpsURLConnection) url.openConnection();
      connect.setDoOutput(true);
      
      connect.setRequestMethod("GET");
      
      BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));

      String decodedString;
      while ((decodedString = in.readLine()) != null) {
        System.out.println(decodedString);
      }
      in.close();


The result I get in the lines:
{
  "kind": "youtube#videoListResponse",
  "etag": "q20uri3_U3aqnEUEbGRnZPlxUbA",
  "items": [
    {
      "kind": "youtube#video",
      "etag": "ESLK6bJzgoGRSORoWeDkjuuzoQ8",
      "id": "vlVQiwYG8eg",
      "statistics": {
        "viewCount": "1618110",
        "likeCount": "38821",
        "dislikeCount": "1160",
        "favoriteCount": "0",
        "commentCount": "1738"
      }
    }
  ],
  "pageInfo": {
    "totalResults": 1,
    "resultsPerPage": 1
  }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
LSP55, 2020-10-23
@LSP55

I found here JSONObject JSONArray JSONParser
Basically it works now

D
Denis Zagaevsky, 2020-10-23
@zagayevskiy

In short, you take Retrofit, Gson, and you get a normal api instead of all that.

O
Orkhan, 2020-10-23
Hasanly @azerphoenix

Greetings!
Look towards the Jackson or GSON libraries.
Using one of the libraries, parse json and get what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question