Java is divided into two types of data, one is the basic data type, one is the reference data type;
Basic data types include Byte/short/int/long (4 integers), float/double (2 floating-point types), char (1-character), Boolean (1-Boolean)
Reference data types: Class classes, interface interface, arrays array
There are two types of JSON data: Jsonobject and Jsonarray
- Jsonobject: {key:value,key:value}, where key is a string type, value is an object type, elements are separated by commas, inner key and value are separated by colons, and the outermost is curly braces
- New Jsonobject:jsonobject obj = new Jsonobject ();
- Add elements to the Jsonobject object: Obj.put (String key, Object object);
- Jsonobject Type Conversions
- From Jsonobjet to String:obj.toString ();
- From string to JSONObject:JSONObject.parseObject (str);
- Gets the value of the element from the Jsonobject object: Obj.getter (String key);
- jsonarray:[element 1, Element 2, Element 3 ...], the outermost side is square brackets
- New Jsonarray object: Jsonarray arr = new Jsonarray ();
- Convert the String type to jsonarray:string str = "[{\" name\ ": \" Zhang San \ "},1234,12.34]"; Jsonarray arr = Jsonarray.parsearray (str);
- Add an element to the Jsonarray object: Array.add (object e);
- Jsonarray Type Conversions
- The Jsonarray type is converted to String type: arr.tostring ();
- The string type is converted to Jsonarray type: Jsonarray.parsearray (string str);
- Extracts the value of an element from a Jsonarray object: array.getter (int index);
- Traverse Jsonarray:
Reprint please indicate the source
JSON data type