关于数组类型的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);


关于数组类型的json解析方法,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。