vk api doing the example link text . I get the answer in the form link text How to display only the last name, first name

  • 3
    It’s necessary to copy-paste mindlessly from pieces of code, but to read [documentation] [1]. In which it is explicitly said that the answer comes in the form of JSON. And “like on java, parse JSON” goes for a second and a half :) [1]: vk.com/dev/api_requests - user6550

1 answer 1

I advise you to use json-simple . There are examples here.

Here is the code for your case:

JSONParser pars = new JSONParser(); Object obj = null; try { obj = pars.parse(response_vk); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject response = (JSONObject) obj; JSONArray arr = (JSONArray) response.get("response"); response = (JSONObject) arr.get(0); String last_name = response.get("last_name").toString(); String first_name = response.get("first_name").toString();