When docking with a third party, the JSON time parameter fields that are returned to us are very common, so it's certainly going to take a while for us to create javabean manually, so we can use JSON to automatically generate JavaBean tools, here's a brief introduction to IntelliJ idea Plug-in Gsonformat in the.
1. What is Gsonformat
Converts the JSON data format into a Java Bean object's as plug-in.
2. Shortcut key ctrl+alt+s, or settings-->plugins-and input Gsonformat install Plugins
After installation, restart IntelliJ idea.
Now generate a corresponding bean from the following JSON string.
{ "Success":true, "msg":"Success", "ErrorCode":20000, "Data":{ "Roomid":123, "isnew":true }}
First you need a new class file (first to create an empty class, nothing),
Copy the JSON you want to parse.
Then Alt+insert pops up the following screen
Formatting JSON
can set
Generated as follows:
Public classResponsevo {/*** success:true * msg: Success * errorcode:20000 * data: {"Roomid": 123, "IsNew": true}*/ Private Booleansuccess; PrivateString msg; Private intErrorCode; PrivateDatabean data; Public Booleanissuccess () {returnsuccess; } Public voidSetsuccess (Booleansuccess) { This. Success =success; } PublicString getmsg () {returnmsg; } Public voidsetmsg (String msg) { This. msg =msg; } Public intGetErrorCode () {returnErrorCode; } Public voidSeterrorcode (intErrorCode) { This. ErrorCode =ErrorCode; } PublicDatabean GetData () {returndata; } Public voidsetData (Databean data) { This. data =data; } Public Static classDatabean {/*** roomid:123 * isnew:true*/ Private intRoomid; Private Booleanisnew; Public intGetroomid () {returnRoomid; } Public voidSetroomid (intRoomid) { This. Roomid =Roomid; } Public Booleanisisnew () {returnisnew; } Public voidSetisnew (Booleanisnew) { This. isnew =isnew; } }}
How to quickly build Java Bean objects from JSON