Parsing JSON files using the Google-gson class library
Use the Jsonparser parser to parse strings and input streams into JSON objects
The code is as follows:
Public classReadjson { Public Static voidMain (string[] args) {Try{jsonparser parser=NewJsonparser (); Jsonobject Object= (Jsonobject) parser.parse (NewFileReader ("Test.json")); System.out.println (Object.get ("Cat"). getasstring ()); System.out.println (Object.get ("Pop"). Getasboolean ()); Jsonarray Languages=object.get ("Language"). Getasjsonarray (); for(intI=0;i<languages.size (); i++) {System.out.println ("*************"); Jsonobject LAN=Languages.get (i). Getasjsonobject (); System.out.println ("Id=" +lan.get ("id"). Getasint ()); System.out.println ("Name=" +lan.get ("name"). getasstring ()); System.out.println ("Ide=" +lan.get ("IDE"). getasstring ()); } } Catch(jsonioexception e) {e.printstacktrace (); } Catch(jsonsyntaxexception e) {e.printstacktrace (); } Catch(FileNotFoundException e) {e.printstacktrace (); } }}
Parsing JSON files using the Google-gson class library