In the application, the user has the ability to insert different url (video for example https://vimeo.com/185441790 ) with vimeo.

There was a need to parse using JSON, but from such a link, similar to the one above, https://vimeo.com/api/v2/video/183364240.json , so that you can get a thumbnail url from it.

With JSON familiar superficially, came across an interesting example c: www.androidhive.info . But here it seems to me a lot of superfluous, could you please orient me in the right direction (I work in the fragment).

  • Do I need to create an additional class HttpHandler.java as shown in the example, or can I put everything in one?
  • Since I don’t need to display this data anywhere, but just get a url, is it possible to shorten my query?
  • In the example, there is a link from which all data is taken in principle, I have a vimeo.com resource, how to correctly specify it in the variable url, and if I have links from this resource will always be different, will it work correctly.
  • Perhaps it would be better to create model objects and use Gson to parse my url?

    1 answer 1

    For your case of JSON, you can get it like this:

     JSONArray jsonArray = new JSONArray(jsonString); String url = ((JSONObject)jsonArray.get(0)).getString("thumbnail_small"); 
    • Thanks for the reaction, but besides that, I still need some method to register? I do not really understand how it works in "alone". You supposedly make a request and get an array in response, right? and how can I use it further, please explain if it is not difficult. - Morozov
    • @VadimMorozov; First, you need to get JSON, which is located by reference, and write it into a variable, for example String jsonString; . Further to use my code which from the received JSON gets the link to a picture. Further with this link you can do whatever you want - Vladyslav Matviienko
    • and how to get JSON is more convenient to get, do not tell? - Morozov
    • one
      @VadimMorozov, JSON is plain text. ESGO can be downloaded as any text. Finding the answer to your question is easy, you will succeed, I believe in you. Simply, if I do it for you, there will be no benefit. - Vladyslav Matviienko
    • Is it possible to implement this through retrofit'a? it seems like I should cut the code, considering that I use this library in the project. - Morozov