1. Building JSON with Gson
Initialization
New Jsonobject ();
Add Property
Jsonobject.addproperty ("Name", Boolean/character/number/string);
To add a sub-level Json
Jsonobject.add ("json_1", jsonobject);
Get JSON element properties
Jsonobject.get ("name"). Getasstring ();
Using Long.parselong Integer.parseint
Get JSON sub-JSON
Jsonobject.getasjsonobject ("json_1");
Array
New Jsonarray ();
Array operations Add get
Jsonarray.add (element); Jsonarray.get (i); // add and get correlation functions
Iterating through an array
for (int i = 0; i < jsonarray.size (); i++) { = (jsonelement) jsonarray.get (i); // take int jsonelement.getasint (); // and so on other type get}
2. Using Fastjson to manipulate JSON
Initialization
New Jsonobject ();
Add to
Jsonobject.put ("name", Object);
Get Child Jsonobject
Jsonobj.getjsonobject ("name");
Get Child Jsonarray
Jsonobj.getjsonarray ("name");
JSON array Additions get
JsonArray.addjsonArray.get
JSON array traversal operations
for (int i = 0; i < jsonarray.size (); i++) { = (jsonobject) jsonarray.get (i); // take int Jsonobject.getintvalue ("name"); // Fetch string Jsonobject.getstring ("name"); // etc other type get}
Java Operation Json