Brief notes on the use of JSON lib class library

Introduction to preface:

JSON lib package is a Java class library, which can convert Java objects (including beans, maps, collections, Java arrays, XML, etc.) and JSON to each other.

Similarly, Google has also launched a class library called gson, which can achieve the same effect. I won't talk about it today.

preparation:

First, we need to download the JSON lib jar package and import the project

Since the method of use is very simple, you can use the code directly here

1. First, write a JSON tool class and pass in 2 parameters, 1 is the JSON identifier (custom), and 2 is the object that needs to be converted into JSON string format

2. Provide a data source class

3. Entity class

4. Test class

The above are four unit test classes. The code is very simple, so we don't need to explain it in words. Let's see the running effect diagram:

Next, let's mention the class library provided by Google: gson

First, it is the same. You need to import the corresponding jar package first

We only need to modify the tool class provided above the article: (the key identifier is missing)

About the use of gson, you can see this brief note: gson brief use note

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
分享
二维码
< <上一篇
下一篇>>