Server requests / JSON parsing - android

What can you recommend in terms of tools for requesting a server and parsing received JSON data? Apart from simple parsing, I might want to map those responses to objects.

Flexjson works on Android for this exact purpose.
http://flexjson.sourceforge.net

Related

How to get some simple data by Internet in Android

I need to get some simple data (actual currency values) to my android application. I'm not sure what is the best way to achieve it. Do I have to make some database and put it on server and than update it manually or there is some better way?
You can use an API Service and access to this service from you android device. You donot need to do a server implementation for this.
e.g. for exchange rates check https://openexchangerates.org/
Yes.
Please make a server and a PHP which going to print out the values in JSON. You can validate your json with http://jsonlint.com/. After it you can download and parse the json with yourself or a 3rd part library (like retrofit).
You can use this website to generate POJO, so retrofit can parse the json for you by it`s own.
http://www.jsonschema2pojo.org/
select: JSON instead of scheme and select GSON instead of JSON, if you are using retrofit.
sources:
https://en.wikipedia.org/wiki/Gson
https://github.com/square/retrofit
http://blog.robinchutaux.com/blog/a-smart-way-to-use-retrofit/

Android - Retrieve data from server database through web service (JSON v/s Servlet)

I need to retrieve huge amounts of data from a database through a web service from an Android app. I have two different ways to do this, and I wanted some advice on it:
1. The first option is to create a .php file on the server side that managed any POST coming from the client (Android app). The server would then create a JSON response. Finally we would parse this response using a JSON parser in Android. This is also known as the REST scheme.
2. The second option is to create a SERVLET, execute it from the client (Android), have the servlet send the request to the database for us, and finally parse that data from Android. Obviously the servlet would be written so that it could easily interact with the database.
Points to note (so as to decide which option is better):
1. I won't be storing anything in the database from the client. That is, my Android app is read-only.
2. I will be reading from a huge database, so it is a priority here the performance of the Client-Server interaction, with a special mention for data parsing and for servlet vs php performance.
Any help would be greatly appreciated.
Android has built-in support for parsing JSON data with the use of JSONObjects and JSONArrays, so it would be a lot easier to handle data in that form, rather than handling servlets. Its even possible to directly receive the web service response as a JSONObject or JSONArray.
In general, web services in Android should be of the RESTful type. That's how Google seems to prefer it. That's why there's built-in support for JSON, but not for SOA or Servlets.
References:
1. Reasons for not directly write Servlets for creating a REST API.
2. Servlet vs REST.

server response xml or json objects android

I have an application which uses restful web services, the service returns a json object.
I wanted to know , what would be better , returning a json or xml response?
Please help as i am new to the concept.
The answer is that it doesn't really matter. They are both almost equivalent. They use slightly different API's so go with the one you feel more comfortable with.
Example of JSON parsing in Android you can find in this question.
Example of XML parsing in Android you can find in this question.
The only reason I can think of to use XML over JSON is when your webservice responses are huge. JSON usually requires the entire response to arrive before you can start parsing. XML easily supports a pull parser which can start parsing "on the fly" before all the data arrives - which can be much more efficient. But if your responses are small, you don't really need all that.
If your existing webservice already returns a JSON object, this could be reason enough to stick with JSON.

Best practice to work with android application and .Net web Api

I have a .net webApi project that contains some methods.
The methods send and get complex objects.
My android application gets the objects in json format and parsing them manually.
In any changes of the objects in the WebApi project I have to change manually the android application project.
I would like to know what is the best practice to work with android application client and .Net WebApi.
There is any tool to connect between them or to auto map the objects?
Please help me
Tal
U do use json parsing technique for parsing the json responses.its proper way of data parsing there is i think no tool for auto mapping.
From the Android Client end you have to use Spring RestTemplate together with Data Transfer Objects (DTOs). You wouldn't need to manually manipulate a JSON String values. It's all about dealing with Java Objects then. You can directly pass the Objects to the RestTemplate as Entity classes and get the JSON String Auto Mapped to your DTOs.

Should i use SOAP or REST in accessing Web service?

i want to access a java web service Running on a Server. which one SOAP or JSON is good to access this web service. i dont want to put overhead on the Server and want the calling of web service to be Fast. plz suggest better way to do this.
JSON and SOAP are two different things. JSON is just a data format while SOAP act as Manager on server side that manage request and response from client.. it can return JSON as a result which is a data format likehttp://stackoverflow.com/questions/9382864/answer/submit XML
You do not access a Web Service with JSON, that is just a format. Depending on the Web Service you might need to communicate with it by sending SOAP envelopes or using REST.
Ok, there is a lot of confusion here. SOAP/REST are two approaches to managing services ON THE SERVER SIDE. SOAP is XML-based, while REST is URL based. Assuming you are writing an Android app, you won't be implementing the SOAP/REST/WSDL interfaces-- you will get them from the service team.
So, if the web service you are using provides both REST and SOAP, then you can choose which set of endpoints to hit.
When you are packaging up your request and sending it to the service, you probably want to package it as JSON. JSON is just "Object Notation." Inherently, it is nothing more than a way to format data in such a way it universally recognized. Alternatively, you can package your request as XML. But JSON is more light-weight, as XML has a lot of required redundancy (unless it is compressed).

Categories

Resources