遇到了非常奇葩的数组类型的json,一时解析不出来,用jsonObject会直接报错。
Json数据如:
[{"id":"1000142","name":"u5168u90e8u7c7bu578b","subMenu":[{"id":"1000135","name":"u591au5a92u4f53u8bbeu8ba1"},{"id":"1000137","name":"javau5f00u53d1"},{"id":"1000138","name":"u524du7aefu5f00u53d1"},{"id":"1000139","name":"phpu5f00u53d1"},{"id":"1000140","name":"IOSu5f00u53d1"},{"id":"1000141","name":"androidu5f00u53d1"}]},{"id":"1000143","name":"u5168u90e8u7b49u7ea7","subMenu":[{"id":"1000146","name":"u9ad8u7ea7"},{"id":"1000145","name":"u4e2du7ea7"},{"id":"1000144","name":"u521du7ea7"}]}]
解决方式:
Type listmenu = new TypeToken<ArrayList<ListMenu>>() { }.getType(); List<ListMenu> menuPage=new Gson().fromJson(json, listmenu);