Use the gson library to convert the map key value corresponding structure object in Java into JSON
•
Java
The storage structure of map is in the form of key / value. Key and value can be ordinary types, JavaBeans written by themselves (this article), or lists with generic types
(gson's GitHub project page: https://github.com/google/gson )
JavaBean
In this example, you will focus on how to define the typetoken when converting JSON back to an ordinary JavaBean object
Entity class:
Test class:
result:
Generic list
Entity class:
Test class:
Output 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
二维码