What is JSON
JSON (JavaScript Object Notation) is a lightweight data exchange format, which is easy to read and write, and easy to parse and generate machines. It is very suitable for the interaction between servers and clients. JSON uses a text format unrelated to the programming language, but it also uses C-like languages. These features make JSON an ideal data exchange format.
Like XML, JSON is also based on plain text data format. Because JSON is designed for JavaScript, The JSON data format is very simple. You can use JSON to transmit a simple String, Number, or Boolean, or an array, or a complex Object.
First create a Web project ServletTest
1: Create a JavaBean named User as the User object class to save the demo data.
2: Create a Servlet class of ServletDemo as the server interface program.
3: deploy the Servlet to Tomcat. You need to modify web. xml for the release project.
4: After the release is successful, enter http: // localhost: 8080/ServletTest/Test in the browser and output the following results:
5: After preparing the server interface, we prepare to write the client program and create an android project.
Create an Activity class named JSONActivity
First, modify the UI layout/main. xml.
6: Core code for the client to obtain network data:
To access the external network, add a security license in the AndroidManifest. xml file:
Run the program
Even if this program is completed, more complex functions can be implemented and will be released later.
This article is from the "Art_Hero" blog