Explain in detail the two ways of interaction between Android and server
Programmers who develop Android must know how the Android client should interact with the server. Here we mainly introduce the interaction using JSON data. The server finds out the data from the database and returns it to the client in the format of JSON string or map set. The client parses and outputs it to the mobile phone screen.
Two methods are introduced here: parsing JSON data using Google's native gson and parsing JSON data using jsonobject
1、 Parse JSON data using Google native gson:
Remember to add gson. Jar on the client side.
Core code:
Server:
client:
Splice URL class:
Class to access the server:
Class to parse JSON data:
The activities and entity classes that call these methods are omitted.
2、 Parsing JSON data using jsonobject
Note: add the jar package of JSON to the server.
Code for client to parse JSON data:
The client receives data from the server:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.