1. parse data using the Button of the main Activity
MainActivity String Data = "{\" name \ ": \" Xiaozhang \ ", \" age \ ": 25, \" sex \ ": \" male \"}; {\ "name \": \ "Plum \", \ "age \": 41, \ "sex \": \ "female \"}; "+" {\ "name \": \ "Qian \", \ "age \": 15, \ "sex \": \ "female \"} "= (Button)
2. Business class for parsing json data
Gson gson = // before the split, it is a whole "{\" name \ ": \" John \ ", \" age \ ": 25, \" sex \": \ "male \" };{\ "name \": \ "Plum \", \ "age \": 41, \ "sex \": \ "female \"};"
= JsonData. split (";" (I = 0; I <users. length; I ++ User user = gson. fromJson (users [I], User. + "," + user. getAge () + "," +
The above method can also be written as follows:
However, it is emphasized that the Data in the main Activity isFormat
"{\" Name \ ": \" John \ ", \" age \ ": 25, \" sex \": \ "male \" }{\ "name \": \ "Plum \", \ "age \": 41, \ "sex \": \ "female \" }{\ "name \": \ "Qian \", \ "age \": 15, \ "sex \": \ "female \"}"
"\" Name \ ": \" John \ ", \" age \ ": 25, \" sex \ ": \" male \ "}{\" name \": \ "Plum \", \ "age \": 41, \ "sex \": \ "female \" }{\ "name \": \ "Qian \", \ "age \": 15, \ "sex \": \ "female \"
"In json format, the above data starts with (braces), and the following strings start with (braces), and each group
().
Gson gson=new Gson();
Type listpyte= TypeToken< LinkedList<User> >(){}.getType();
LinkedList<User> users= (Iterator<User> iterator= User user= System.out.println(user.getName()+","+user.getAge()+","+ }
3. The Class Object implementing data parsing is the User class here.
.name = setAge( .age = .sex = }
4. Before running, copy the Google Gson-xxx.jar file to the libs folder in the project.