Encounter [
{"ID": "6", "catid": "0", "title": "\ u5c0f \ u767d", "style": "", "Thumb ": "", "keywords": "", "Description": "", "posids": "0", "url": "index. PHP? M = YP & C = index & A = show & catid = & id = 6 "," listorder ":" 0 "," status ":" 99 "," userid ": "1", "username": "zhanghao", "inputtime": "1349156280", "updatetime": "1349156280", "Elite": "0", "name_py ": "Xiaobai", "class_id": "2", "class": "\ u5c0f \ u7eff \ u73ed", "bj_id": "2", "cou_id ": [{"title": "\ u5218 \ u6052 \ u5fd7" },{ "title": "\ u5f20 \ u6d69" },{ "title ": "\ u674e \ u5c0f \ u9f99" },{ "title": "\ u5c0f \ u864e"}]},
{"Id": "5", "catid": "0", "title": "\ u5c0f \ u7ea2", "style": "", "thumb ": "", "keywords": "", "description": "", "posids": "0", "url": "index. php? M = yp & c = index & a = show & catid = & id = 5 "," listorder ":" 0 "," status ":" 99 "," userid ": "1", "username": "zhanghao", "inputtime": "1349156249", "updatetime": "1349156249", "elite": "0", "name_py ": "xiaohong", "class_id": "2", "class": "\ u5c0f \ u7eff \ u73ed", "bj_id": "2", "cou_id ": [{"title": "\ u5218 \ u6052 \ u5fd7" },{ "title": "\ u5f20 \ u6d69" },{ "title ": "\ u674e \ u5c0f \ u9f99" },{ "title": "\ u5c0f \ u864e"}]
Fields contain arrays. Note the following when parsing with gson:
The brown mark is A large object (marked as class A), and the red mark can be marked as an object class B. In this way, when declaring A, List <B> cou_id; it is a member variable, String title; it is a member variable of B and can be parsed by gson. Take a look at the Code:
Type listType = new TypeToken <shortlist <Baby> (){}. getType (); Gson gson = new Gson (); sort list <Baby> babys = gson. fromJson (jsonData, listType); // The User object will be saved to the User list System. out. println (babys. size (); for (Baby baby: babys) {System. out. println (baby );}