JSON data is generally divided into two types, object and array.
JSON parsing requires write exception handling.
The JSON object is parsed using the Jsonobject class, such as
Public voidAnalys_jsonobject (String jsondata) {//Jsondata is the JSON data in the object format Try{jsonobject Jsonobject=NewJsonobject (Jsondata); String one_string= Jsonobject.getstring ("Key value name");//get a string by key-value nameJsonobject one_jsonobject = Jsonobject.getjsonobject ("Key value name");//get the JSON object in object format by key value nameJsonarray One_jsonarray = Jsonobject.getjsonarray ("Key value name");//get array-formatted JSON objects with key-value names}Catch(Exception e) {e.printstacktrace (); } }
The Jsonarray class uses similar:
Public voidAnalys_jsonarray (String jsondata) {//Jsondata is the JSON data in the array format Try{Jsonarray Jsonarray=NewJsonarray (Jsondata); String One_json= jsonarray.getstring (0);//extracting data by int type numbersJsonobject one_jsonobject = jsonarray.getjsonobject (0);//Get Object-formatted JSON objects with int numbersJsonarray One_jsonarray = jsonarray.getjsonarray (0);//get array-formatted JSON objects with int numbers}Catch(Exception e) {e.printstacktrace (); } }
Java parsing JSON data