Array json Parsing Method
An error is reported directly when jsonObject is used because json of the array type cannot be parsed.
Json data such:
[{"Id": "1000142", "name": "\ u5168 \ u90e8 \ u7c7b \ u578b", "subMenu": [{"id": "1000135 ", "name": "\ u591a \ u5a92 \ u4f53 \ u8bbe \ u8ba1" },{ "id": "1000137", "name": "java \ u5f00 \ u53d1 "}, {"id": "1000138", "name": "\ u524d \ u7aef \ u5f00 \ u53d1" },{ "id": "1000139", "name ": "php \ u5f00 \ u53d1" },{ "id": "1000140", "name": "IOS \ u5f00 \ u53d1" },{ "id": "1000141 ", "name": "android \ u5f00 \ u53d1"}] },{ "id": "1000143", "name": "\ u5168 \ u90e8 \ u7b49 \ u7ea7 ", "subMenu": [{"id": "1000146", "name": "\ u9ad8 \ u7ea7" },{ "id": "1000145", "name ": "\ u4e2d \ u7ea7" },{ "id": "1000144", "name": "\ u530d \ u7ea7"}]
Solution:
Type listmenu = new TypeToken<ArrayList<ListMenu>>(){}.getType();List<ListMenu> menuPage=new Gson().fromJson(json, listmenu);
How to parse json arrays similar to MAP types?
Json is generally parsed using an existing library, and no one parses it by themselves. LZ goes to the next one on the Internet.
How to parse json into an array
Each element in the province array is a map record province name and province City
The city is also a map to record the city name and the city's county layer-by-layer nesting, and finally converted to the json format toString () Output Using JSONObject