java 遍历json数组

json数组:[
{"first_id":1,"first_name":"中学","second_id":1-1,"second_name":"一年级","third_id":1-1-1,"third_name":"一年级一班","people":10},
{"first_id":1,"first_name":"中学","second_id":1-1,"second_name":"一年级","third_id":1-1-2,"third_name":"一年级二班","people":11},
{"first_id":1,"first_name":"中学","second_id":1-2,"second_name":"二年级","third_id":1-2-1,"third_name":"二年级一班","people":20},
{"first_id":1,"first_name":"中学","second_id":1-2,"second_name":"二年级","third_id":"1-2-2","third_name":"二年级一班","people":21},
{"first_id":2,"first_name":"高中","second_id":2-1,"second_name":"一年级","third_id":2-1-1,"third_name":"一年级一班","people":31},]
对上面json数组遍历成下面的样子
[{
"id":1,
"name":"中学",
"children":[{
"id":1-1,
"name":"一年级",
"children":[{
"id":1-1-1,
"name":"一年级一班",
"people":10,
},{"id":1-1-2,"name":"一年级二班","people":11}]},{"id":1-2,"name":"二年级",
"children":[{
"id":1-2-1,
"name":"二年级一班",
"people":20
},{
"id":1-2-2,
"name":"二年级一班",
"people":21}]}]},{"id":2,
"name":"高中",
"children":[{
"id":2-1,
"name":"一年级",
"children":[{
"id":2-1-1,
"name":"一年级一班",
"people":31}]}]}]
求大神用java帮忙写下

你的这个问题确实需要点时间;

我个人的思路是用 HashMap 和 List 这两种数据结构;

如果你了解二叉数的话,在用我说的上面的两种数据结构;

是能解决问题的;

如果对回答满意,请点【采纳答案】,如果还有问题,请点【追问】

希望我的回答对您有所帮助,希望能采纳。
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-01-16

现写了一个,本地测试完全满足你的要求,现把源代码和用到的jar包传为附件。有什么不会用的再追问。

追问

谢谢哈 厉害哈 刚刚结果有点变化 能不能再帮忙看下 ,谢谢了
http://zhidao.baidu.com/question/1691056659884248908.html

本回答被提问者采纳
相似回答