How to send object through HttpURLConnection without using json in android? - android

Is it possible to send user defined objects through HttpURLConnection without using json in android ? For example: I am creating one class and I want to send that class object without using json. Is it possible? If it is, how to proceed?

Yes, it is possible, but you have to write/read data into streams manually. That is why JSON is good way for doing that- all data is already formatted and is in String representation. If you don't want to bother yourself with parsing objects to/from Json, use Gson library from Google

Related

Do I need to parse the complete json using moshi on Android?

If there is a Rest-API where I get a very large JSON but I only need a few fields of it, for example only the first block in it, do I need to manually create kotlin data classes for ALL the fields in the JSON to be able to parse work with json data? What's the current best practice of handling such a case?

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/

Simple Android JSON Parsing

Hello, I am a newbie to android development
I am trying to understand how to parse JSON in android activity
I am not using anything such as PHP etc
I am using NODEJS on server in AWS to generate JSON
I have a JSON ::
{"1":"Hello","2":"World"}
This JSON is coming from an AWS server i have hosted my application
How to parse the JSON data for above JSON ?
How to populate to an android activity ?
PS:: Any links that would help me understand this concept would also be helpful
Thanks,
In the most basic form, you can parse JSON by simply creating a JSON object and passing the string representation of the JSON object to the constructor, like so...
JSONObject myJson = new JSONObject("{\"1\":\"Hello\",\"2\":\"World\"}");
Read the docs on this class for more info on how to extract data from objects and etc... https://developer.android.com/reference/org/json/JSONObject.html
A more abstract way of parsing can be done via the GSON library. In a nutshell, GSON has the ability to take your JSON response and parse it into a Java object for you so that you don't have to do it yourself.
Admittedly using GSON can save a good amount of time from writing code to parse yourself, however, I would probably rather go the JSONObject route if you're new to this.

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.

send json object using http post method for android application

i am trying to send JSON object to my php webservice.
I have referred this url :- http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/
In my web service, I have to pass username and password but i don't know,
what is the GSON. can you tell why GSON use in this.????
I am new in json. if you know about json please guide me to solve this problem.
GSON is a Java library to convert java objects to JSON and vice-versa. You don't need it unless you have some complex JSON structure. For simple objects you can easily construct the JSON string yourself.

Categories

Resources