import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; public class ParseWorkFlow { public static void main (String[] args) throws java.lang.Exception { String USER_AGENT = "Mozilla/5.0"; final String request = "https://api.vk.com/method/database.getUniversities"; int[] CitiesToParse = {1, 2}; //массив с нужными городами List<String> universities = new ArrayList<>(); //массив с результатом парса(все еще в JSON) for(int i = 0; i < CitiesToParse.length; i++) { String urlString = request + "?city_id=" + (int)CitiesToParse[i] + "&count=2"; URL url = new URL(urlString); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); String output; StringBuffer response = new StringBuffer(); while ((output = in.readLine()) != null) { response.append(output); } in.close(); String strParseResult = response.toString(); System.out.println(strParseResult); universities.add(strParseResult); } } } At the end of the code for the test led the result to a string and displayed on the screen.
The code issues the following:
{"response":[713,{"id":2,"title":"МГУ"},{"id":86,"title":"АПИ при ИГиП РАН"}]} {"response":[289,{"id":1,"title":"СПбГУ"},{"id":5,"title":"АРБ им. Вагановой"}]} There is a GSON library. With her I want to parse the result.
I insert in http://www.jsonschema2pojo.org/ , I receive one class. (it seems to me not exactly what you need)
Help parse. The whole brain broke already.