如何处理这组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项重复;本意效果是
![](http://images0.cnblogs.com/blog/555444/201410/182226586079296.jpg)
但实际效果是
![](http://images0.cnblogs.com/blog/555444/201410/182226587942240.jpg)
============解决方案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>();