When accessing the site we get json object

{ userId: 32, firstName: "Алексей", lastName: "Голобурдин", address: { country: "Россия", city: "Москва" }, phone: "8 (905) 777 77 77" } 

how to parse it with jsoup

 JSONObject obj=new JSONObject(); obj = Jsoup.connect(URL).ignoreContentType(true).execute().body(); 

gives an error message.

  • one
    With the help of jsoup - no way. Look for the json parser. - Dmitriy
  • which one gives an error? - Roman C
  • error: variable obj is already in the doInBackground (Void ...) - Andrey Kruzlik
  • @ AndreiKruzlik, rename obj - Nick

1 answer 1

Line:

 obj = Jsoup.connect(URL).ignoreContentType(true).execute().body(); 

it does not even compile, because .body() returns a String , and the left-hand side is of type JSONObject

JSONObject (from the org.json package) has a constructor that accepts String :

 String jsonString = Jsoup.connect(URL).ignoreContentType(true).execute().body(); JSONObject obj = new JSONObject(jsonString);