How to get JSON data for any website to parse and use in my android native app

13,006

Let me answer your questions, even though they're a bit vague.

Is my understanding correct?

Yes, it is, you can make Http calls to the web API and get and parse the JSON response according to your needs.

If yes, should I just ask the developer (or) find that info someplace (posted for use) to know how to access the json data for their website and use it in my code? (or) is there something else I need to do?

Of course, if you know the developer, you should ask him. Most of the popular websites who have open API's have some kind of documentation about their JSON responses. A good example is taking a look at reddit's API, you can get any page as a JSON response by simply attaching /.json at the end of any url. This might prove useful if you want to practice parsing json and sending http requests. I'd recommend using OkHttp library for this.

If the developer has to provide the info for JSON, what should I specifically ask for? and What will the developer provide me?

This question I find the most difficult one to answer since it's a bit vague. You ask what you need and what is the request you need to send to get it.

What this means is what parameters your request should have (the best example being if the site uses authentication, does it use oauth or something else, do you need to first log in and get an access_token as is usually a case). This can vary tremendously depending on what you're trying to get, some requests are POST, some are GET and might not even require any additional parameters etc.

For example if you want to get a list of, for example, all cars from a website, you'd ask or search for a route that returns a JSONArray of cars and you'd presumably wanna send a GET request to that route (with access_token parameter if they use oauth, just an example) and you'd receive a respone, which may look something like this:

{ 
   [ {"id" : "1",
    "manufacturer" : "bmw",
    "model" : "320d"},
    {"id" : "1",
    "manufacturer" : "audi",
    "model" : "A6"}
   ]
}

This is purely for demonstrative purposes. The JSON may be arbitrarily more or less complicated, and you can parse it according to your needs, you might wanna use just some of the data contained there. There are a lot of questions on the topic of json parsing, so I won't get into that any further.

I hope this was informative to you, and if you're looking to make your own API, there are a lot of ways you can do this, you can also find many tutorials on this topic. I've done this in Laravel and Symfony PHP frameworks, and let me tell you, it's not that hard at all. All you need to do is always return a JSON and that's basically it.

Share:
13,006

Related videos on Youtube

App Developer
Author by

App Developer

Updated on June 04, 2022

Comments

  • App Developer
    App Developer almost 2 years

    My understanding is that as an android developer in order to develop native android apps for existing web applications built using Spring MVC or PHP or Angular JS, I need to access the data in JSON format and use in my android app as per my needs. For this I don't have to know anything about the web frameworks which were used to build the websites.

    1. Is my understanding correct? If no, please correct my understanding.

    2. If yes, should I just ask the developer (or) find that info someplace (posted for use) to know how to access the json data for their website and use it in my code? (or) is there something else I need to do?

    3. If the developer has to provide the info for JSON, what should I specifically ask for? and What will the developer provide me?

    Thanks for your help in advance!

    • Luke Hutton
      Luke Hutton over 7 years
      What do you mean any website? What are you building your app for and for what website do you want data for? Some companies provide public apis which in turn return json data and each one varies on how to use it, i.e. authentication like oauth2, etc.
    • App Developer
      App Developer over 7 years
      I ask this only for the sake of gaining clarity on how it works conceptually at this time and an aspiring android developer. 2 Scenarios can be considered. Let us say the company I will work is developing a web application using Spring MVC. They also want to have a custom android native app developed for the website. I have been hired as an android developer and asked to do the job. There are other web app developers in the team. For
    • App Developer
      App Developer over 7 years
      I ask this only for the sake of gaining clarity on how it works conceptually and an aspiring android developer. Let us say the company I will work for is developing a web application using Spring MVC. They also want to have a custom android native app developed for the website. I have been hired as an android developer and asked to do the job. There are other web app developers in the team. how do I get the data to used in my andr app. Should I ask to developer for the info or should I know something to get the job done even without having to communicate with the developer?
    • Luke Hutton
      Luke Hutton over 7 years
      Yes, you will typically be provided with apis to the backend, regardless of the tech stack. A good company will have some internal docs and examples of how to use it. Hopefully you can work closely with the api team while you integrate. And communication is a good thing, I work on apis and the app dev sits right in front of me, it's ok to talk to eachother , and in fact encouraged :)
    • App Developer
      App Developer over 7 years
      Great! Thank you. That's what I wanted to know.
  • App Developer
    App Developer over 7 years
    Great! Thanks, I think I got my answer.
  • App Developer
    App Developer over 7 years
    I was reading in order and have appreciated both of you! Upvoted your answer! Thanks again!