Now I will only in the two data below, now see a lot of information on the net, json is a little bit confused,
CodePudding user response:
You can start to build an object or a Map to your id, num, price as the key attribute of an object or a Map, and then the object with library and Map into a json format string output responseCodePudding user response:
/* *
* generate json string objects
*
* @ param & lt; T>
* @ param t
* @ return
*/
Public static & lt; T> String toJson (T T) {
Objects. RequireNonNull (t);
Return new Gson (). ToJson (t);
}
/* *
* generate json string Map
*
* @ param map
* @ return
*/
Public static String toJson (MapMap) {
If (null==map | | map. The isEmpty ()) {
Return "{}";
}
Type gsonType=new TypeToken