Java uses gson to parse JSON data instances

JSON (JavaScript object notation) is a lightweight data exchange format, which is easy to read and write, and easy to machine parse and generate. It is a "transport format" like XML. JSON adopts text format independent of programming language, which is convenient for data transmission, storage and exchange.

Encapsulation class attribute:

Another encapsulation class, gsondataanalysis:

Test class main method:

Note: when using gson class, gson should be added to the project Jar package.

Now let's introduce Java parsing JSON format data

Sometimes JSON format may be used for data transmission, so how to parse the received data? Here are two methods for parsing JSON data:

1. Parse through Google's gson:

JSON data: stotalstring = {"message": "success", "result": [{"surveyid": "1", "surveyname": "B"} {surveyid ":" 2 "," surveyname ":" C "}]};

Two VO classes:

Convert JSON format to object type:

2. Via json-org.org Jar package for parsing:

JSON data: stotalstring = {"message": "success", "surveyname": "C"}]};

A VO class:

Convert JSON format to object type:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>