Detailed explanation of three ways to parse JSON based on Java

This paper analyzes three ways of parsing JSON based on Java. Share with you for your reference, as follows:

1、 What is JSON?

JSON is a data structure that replaces XML. Compared with XML, it is smaller, but its description ability is not poor. Due to its small size, the network data transmission will reduce more traffic and speed up the speed.

JSON is a string, but elements are marked with specific symbols.

{} double parentheses denote object [] Middle parentheses denote array ''. Within double quotation marks are attributes or values: colons denote that the latter is the value of the former (this value can be a string, a number, or another array or object)

Therefore, {"name": "Michael"} can be understood as an object with the name Michael

[{"name": "Michael"}, {"name": "Jerry"}] represents an array containing two objects

Of course, you can also use {"name": ["Michael", "Jerry"]} to simplify the above part, which is an object with a name array

2、 Traditional JSON parsing

1. Generate JSON string

2. Parsing JSON strings

There are three cases: a JavaBean, a list array, and a list array of nested maps:

3、 JSON parsing gson

1. Generate JSON string

2. Parsing JSON

4、 Fastjson for JSON parsing

Summary:

JSON for mobile devices, especially in the case of poor network environment and traffic restrictions, data transmission in XML format will save traffic and have higher transmission efficiency. Among the three parsing methods, fastjason is the most efficient and is recommended.

PS: About JSON operation, here are some more practical JSON online tools for your reference:

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