Gson implements JSON serialization and deserialization of Java objects

Download gson from GitHub: https://github.com/google/gson The application of gson mainly includes two conversion functions: tojason and fromjason. Before using this object conversion, you need to create the object category and its members to successfully convert the JSON string into the corresponding object.

Serialize Java objects into JSON strings

The JSON result will be

Deserialize the JSON string into the corresponding Java object

==>Example2 is the same as cexample1

The object example1 is serialized into JSON string through tojson, and then an object example2 is declared to be deserialized into example2 through fromjson after receiving JSON. Therefore, example1 is the same as example2

Example:

Operation results:

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