如何处理这组Json
============问题描述============
[{"id":2,"grade":"2016级","class:"1班"},{"id":3,"grade":"2016级","class":"2班"},{"id":,4,"grade":"2016级","class":"3班"},{"id":5,"grade":"2015级","class":"1班"}]
已经成功解析,但里面的grade键值对很多值是大量重复的。用listview或Expandablelistview 会出项group项重复;本意效果是
但实际效果是
============解决方案1============
可以重新设计json格式为:
[ { "grade": "2015级", "classes": [ {"id": 5, "class": "1班"} ] }, { "grade": "2016级", "classes": [ {"id": 2, "class": "1班"}, {"id": 3, "class": "2班"}, {"id": 4, "class": "3班"} ] } ]
或者把数据对象组织为:
class Class { int id; String name; } class Grade { String name; ArrayList<Class> classes; } ArrayList<Grade> grades = new ArrayList<Grade>();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。