Srikanth Ganesan Srikanth Ganesan - 5 months ago 30
AngularJS Question

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

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!

Answer

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.