The first kind: use Net.sf.json hard solution. Disadvantage: Requires field names and field names in JSON strings, field naming violates hump rules and is not conducive to expansion;
Jsonarray Jsonarray = Jsonarray.fromobject (str);
Jsonobject jobj = jsonarray.getjsonobject (0);
User user= (user) Jobj.tobean (jobj,user.class);
The second type: Parse the JSON string with Gson. Advantages: Simple writing, the field name as long as the use of @serializedname annotations, can be used to make the object field and JSON one by one corresponding; disadvantage: parsing a string such as a JSON array a little bit troublesome
Gson Gson = new Gson ();
User user= Gson.fromjson (msg, user.class);
The Third Kind: use Jackson to parse. Pros: As with Gson parsing, field names can use @jsonproperty annotations;
Objectmapper mapper = new Objectmapper ();
User user= mapper.readvalue (msg, user.class);
Java parsing JSON strings in multiple ways