Android JSON network data exchange

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.