关于数组类型的json解析方法
遇到了非常奇葩的数组类型的json,一时解析不出来,用jsonObject会直接报错。
Json数据如:
[{"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":"\u521d\u7ea7"}]}]
解决方式:
Type listmenu = new TypeToken<ArrayList<ListMenu>>() { }.getType(); List<ListMenu> menuPage=new Gson().fromJson(json, listmenu);