Gson的使用——Gson解析json数组并展示在ListView控件上

时间:2022-05-12 19:41:41

类似于解析json数据的框架有很多,常用的就是Gson,使用起来特别的方便,同时,还拥有很好的可操作性,今天就来说说怎么用Gson去解析一个json数组。使用Gson之前,需要下载一个gson.jar的jar包。具体的自己去网上下载,有很多。

首先看看数据源

<code class="hljs json has-numbering">{
"<span class="hljs-attribute">a</span>": <span class="hljs-value">[
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"1"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"艾勇"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"aiyong"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/niul7b2sdy.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"2"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"安京哲"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"anjingzhe"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/tfnc4pko7n11ul.jpg"</span>
</span>}
]</span>,
"<span class="hljs-attribute">b</span>": <span class="hljs-value">[
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"351"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"白雪剑"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"baixuejian"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/31dl12sfmjo.png"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"3"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"白振亮"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"baizhenliang"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/rrqixinqap.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"4"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"毕伟"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"biwei"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/7rhytjvhmg8q.jpg"</span>
</span>}
]</span>,
"<span class="hljs-attribute">c</span>": <span class="hljs-value">[
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"5"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"曹恒海"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"caohenghai"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/0iru1ef1w0k58.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"6"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"曹润星"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"caorunxing"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/mdk1rliogrk.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"377"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"曹显龙"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"caoxianlong"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"447"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"测试用户"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"ceshiyonghu"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"456"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"测试专员"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"ceshizhuanyuan"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"7"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"柴宁"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chaining"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/nqyrnb2gahql.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"8"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"常传泉"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"changchuanquan"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/rbbf5xpwn7a.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"453"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"查芃"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chapeng"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"13"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈锴"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chen"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"16"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈琪"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chen"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/agogbyaf9tmfwjqf.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"10"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈飞"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenfei"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/pi6aa9p5q7envo2k.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"413"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"成建新"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chengjianxin"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"21"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"程晟"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chengsheng"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/hkthw4jent6czg.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"22"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"程树森"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chengshusen"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/kf7278h7t832u6.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"458"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"程序员"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chengxuyuan"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"11"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈海滨"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenhaibin"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"432"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈捷"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenjie"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"12"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈津川"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenjinchuan"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/59amjj1fe3f.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"14"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈娜娜"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chennana"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/fq82mj0xpt.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"15"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈鹏"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenpeng"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"17"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈青溪"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenqingxi"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/r9a3wtcf88b.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"19"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈奕超"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenyichao"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/izsp4r3yx.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"20"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"陈宗敏"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chenzongmin"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/syewiyta6g42cv8.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"9"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"车永超"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"cheyongchao"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/sj68k9ope6r.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"23"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"迟迅"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chixun"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"24"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"褚海涛"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"chuhaitao"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/8bwltpuwf.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"26"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"崔凤祥"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"cuifengxiang"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/g48ihbkfd2itf43.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"27"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"崔锦锋"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"cuijinfeng"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"28"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"崔亚强"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"cuiyaqiang"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/jcpfeegotnik1pp.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"397"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"崔艺"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"cuiyi"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/3kt4hrsm3qmfb5.jpg"</span>
</span>}
]</span>,
"<span class="hljs-attribute">d</span>": <span class="hljs-value">[
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"29"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"戴新民"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"daixinmin"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/vnndoq3rw8ekk.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"30"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"邓丽"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"dengli"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/hnow6jn58k.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"32"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"丁炜"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"dingwei"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/qt9tsrsied.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"440"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"董梦石"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"dongmengshi"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/r0vsa2w39xq07.png"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"33"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"杜锴"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"du"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/ytig406nljeyef.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"34"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"段宝平"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"duanbaoping"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/rv7az0zbo.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"35"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"段海鹰"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"duanhaiying"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/xbquyz6kmga28.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"36"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"段江"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"duanjiang"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"403"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"段炼"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"duanlian"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/curi2er7ti.jpg"</span>
</span>},
{
"<span class="hljs-attribute">numid</span>": <span class="hljs-value"><span class="hljs-string">"37"</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"段拓文"</span></span>,
"<span class="hljs-attribute">abbreviation</span>": <span class="hljs-value"><span class="hljs-string">"duantuowen"</span></span>,
"<span class="hljs-attribute">photo</span>": <span class="hljs-value"><span class="hljs-string">"/test/qingqixie/Public/Upload/jstsdb0afmu4xha.jpg"</span>
</span>}
]
</span>}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li><li>82</li><li>83</li><li>84</li><li>85</li><li>86</li><li>87</li><li>88</li><li>89</li><li>90</li><li>91</li><li>92</li><li>93</li><li>94</li><li>95</li><li>96</li><li>97</li><li>98</li><li>99</li><li>100</li><li>101</li><li>102</li><li>103</li><li>104</li><li>105</li><li>106</li><li>107</li><li>108</li><li>109</li><li>110</li><li>111</li><li>112</li><li>113</li><li>114</li><li>115</li><li>116</li><li>117</li><li>118</li><li>119</li><li>120</li><li>121</li><li>122</li><li>123</li><li>124</li><li>125</li><li>126</li><li>127</li><li>128</li><li>129</li><li>130</li><li>131</li><li>132</li><li>133</li><li>134</li><li>135</li><li>136</li><li>137</li><li>138</li><li>139</li><li>140</li><li>141</li><li>142</li><li>143</li><li>144</li><li>145</li><li>146</li><li>147</li><li>148</li><li>149</li><li>150</li><li>151</li><li>152</li><li>153</li><li>154</li><li>155</li><li>156</li><li>157</li><li>158</li><li>159</li><li>160</li><li>161</li><li>162</li><li>163</li><li>164</li><li>165</li><li>166</li><li>167</li><li>168</li><li>169</li><li>170</li><li>171</li><li>172</li><li>173</li><li>174</li><li>175</li><li>176</li><li>177</li><li>178</li><li>179</li><li>180</li><li>181</li><li>182</li><li>183</li><li>184</li><li>185</li><li>186</li><li>187</li><li>188</li><li>189</li><li>190</li><li>191</li><li>192</li><li>193</li><li>194</li><li>195</li><li>196</li><li>197</li><li>198</li><li>199</li><li>200</li><li>201</li><li>202</li><li>203</li><li>204</li><li>205</li><li>206</li><li>207</li><li>208</li><li>209</li><li>210</li><li>211</li><li>212</li><li>213</li><li>214</li><li>215</li><li>216</li><li>217</li><li>218</li><li>219</li><li>220</li><li>221</li><li>222</li><li>223</li><li>224</li><li>225</li><li>226</li><li>227</li><li>228</li><li>229</li><li>230</li><li>231</li><li>232</li><li>233</li><li>234</li><li>235</li><li>236</li><li>237</li><li>238</li><li>239</li><li>240</li><li>241</li><li>242</li><li>243</li><li>244</li><li>245</li><li>246</li><li>247</li><li>248</li><li>249</li><li>250</li><li>251</li><li>252</li><li>253</li><li>254</li><li>255</li><li>256</li><li>257</li><li>258</li><li>259</li><li>260</li><li>261</li><li>262</li><li>263</li><li>264</li><li>265</li><li>266</li><li>267</li><li>268</li><li>269</li><li>270</li><li>271</li><li>272</li><li>273</li><li>274</li><li>275</li><li>276</li><li>277</li><li>278</li><li>279</li><li>280</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

这个是一个比较具有代表性的json数据。先大体的分析一下数据,最外面的是一个json对象,里面有四个json数组。那么进行第一、步,先建立实体类,当然了,这么多的数据,不可能让我们一个个的去写,我们这里要引用一个工具,他会帮我生成实体类。
网址如下:http://www.bejson.com/json2javapojo/

这里为了方便,我就把这个数据放在了assets目录下,取名为text.txt 。

好了,数据源有了,实体类也建好了,那么就可以开始我们的编码了。首先是从assets取出数据,代码如下:

<code class="hljs cs has-numbering"><span class="hljs-keyword">try</span> {
String data;
InputStream <span class="hljs-keyword">is</span>;
<span class="hljs-keyword">is</span>=getResources().getAssets().open(<span class="hljs-string">"text.txt"</span>);
<span class="hljs-keyword">byte</span>[] b = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-keyword">is</span>.available()];
<span class="hljs-keyword">is</span>.read(b);
data = <span class="hljs-keyword">new</span> String(b);
} <span class="hljs-keyword">catch</span> (Exception e) {
<span class="hljs-comment">// TODO Auto-generated catch block</span>
e.printStackTrace();
}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

这个data就是我们的json数据了,接下来就是实现解析的操作了。这里我写成了一个方法。具体代码如下:

<code class="hljs lasso has-numbering"><span class="hljs-comment">/*
* 解析数据
*/</span>
<span class="hljs-keyword">public</span> <span class="hljs-literal">void</span> analysisData(<span class="hljs-built_in">String</span> <span class="hljs-built_in">data</span>) {
try {
<span class="hljs-comment">// Type listType = new TypeToken<List<Root>>() {</span>
<span class="hljs-comment">// }.getType();</span>
oList <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> ArrayList<span class="hljs-subst"><</span><span class="hljs-built_in">Map</span><span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">>></span>();
<span class="hljs-built_in">List</span><span class="hljs-subst"><</span>Root<span class="hljs-subst">></span> appinfos <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> ArrayList<span class="hljs-subst"><</span>Root<span class="hljs-subst">></span>();
Root depts <span class="hljs-subst">=</span> gson<span class="hljs-built_in">.</span>fromJson(<span class="hljs-built_in">data</span>, Root<span class="hljs-built_in">.</span>class);
appinfos<span class="hljs-built_in">.</span>add(depts);

for (int i <span class="hljs-subst">=</span> <span class="hljs-number">0</span>; i <span class="hljs-subst"><</span> appinfos<span class="hljs-built_in">.</span>size(); i<span class="hljs-subst">++</span>) {

root <span class="hljs-subst">=</span> appinfos<span class="hljs-built_in">.</span>get(i);
<span class="hljs-built_in">List</span><span class="hljs-subst"><</span>A<span class="hljs-subst">></span> listA <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> ArrayList<span class="hljs-subst"><</span>A<span class="hljs-subst">></span>();
<span class="hljs-built_in">List</span><span class="hljs-subst"><</span>B<span class="hljs-subst">></span> listB <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> ArrayList<span class="hljs-subst"><</span>B<span class="hljs-subst">></span>();

listA <span class="hljs-subst">=</span> root<span class="hljs-built_in">.</span>getA();
for (int j <span class="hljs-subst">=</span> <span class="hljs-number">0</span>; j <span class="hljs-subst"><</span> listA<span class="hljs-built_in">.</span>size(); j<span class="hljs-subst">++</span>) {
<span class="hljs-built_in">Map</span><span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">></span> <span class="hljs-built_in">map</span> <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> HashMap<span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">></span>();
a <span class="hljs-subst">=</span> listA<span class="hljs-built_in">.</span>get(j);

<span class="hljs-built_in">map</span><span class="hljs-built_in">.</span>put(<span class="hljs-string">"name"</span>, a<span class="hljs-built_in">.</span>getName());
<span class="hljs-built_in">map</span><span class="hljs-built_in">.</span>put(<span class="hljs-string">"photo"</span>, a<span class="hljs-built_in">.</span>getPhoto());
oList<span class="hljs-built_in">.</span>add(<span class="hljs-built_in">map</span>);
}
listB <span class="hljs-subst">=</span> root<span class="hljs-built_in">.</span>getB();
oList2 <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> ArrayList<span class="hljs-subst"><</span><span class="hljs-built_in">Map</span><span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">>></span>();
for (int j <span class="hljs-subst">=</span> <span class="hljs-number">0</span>; j <span class="hljs-subst"><</span> listB<span class="hljs-built_in">.</span>size(); j<span class="hljs-subst">++</span>) {
<span class="hljs-built_in">Map</span><span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">></span> <span class="hljs-built_in">map</span> <span class="hljs-subst">=</span> <span class="hljs-literal">new</span> HashMap<span class="hljs-subst"><</span><span class="hljs-built_in">String</span>, Object<span class="hljs-subst">></span>();
b <span class="hljs-subst">=</span> listB<span class="hljs-built_in">.</span>get(j);

<span class="hljs-built_in">map</span><span class="hljs-built_in">.</span>put(<span class="hljs-string">"name"</span>, b<span class="hljs-built_in">.</span>getName());
<span class="hljs-built_in">map</span><span class="hljs-built_in">.</span>put(<span class="hljs-string">"photo"</span>, b<span class="hljs-built_in">.</span>getPhoto());
oList2<span class="hljs-built_in">.</span>add(<span class="hljs-built_in">map</span>);
}
oList<span class="hljs-built_in">.</span>addAll(oList2);

}

mListView<span class="hljs-built_in">.</span>setAdapter(<span class="hljs-literal">new</span> MyAdapter(oList, this));

} catch (Exception e) {
e<span class="hljs-built_in">.</span>printStackTrace();
}

}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

截止目前,这些数据就解析完成了。当然,可能看起来云里雾里,下面贴上所有的代码:
布局文件:activity_main.xml

<code class="hljs xml has-numbering"><span class="hljs-tag"><<span class="hljs-title">RelativeLayout</span> <span class="hljs-attribute">xmlns:android</span>=<span class="hljs-value">"http://schemas.android.com/apk/res/android"</span>
<span class="hljs-attribute">xmlns:tools</span>=<span class="hljs-value">"http://schemas.android.com/tools"</span>
<span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"match_parent"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"match_parent"</span>
<span class="hljs-attribute">android:paddingBottom</span>=<span class="hljs-value">"@dimen/activity_vertical_margin"</span>
<span class="hljs-attribute">android:paddingLeft</span>=<span class="hljs-value">"@dimen/activity_horizontal_margin"</span>
<span class="hljs-attribute">android:paddingRight</span>=<span class="hljs-value">"@dimen/activity_horizontal_margin"</span>
<span class="hljs-attribute">android:paddingTop</span>=<span class="hljs-value">"@dimen/activity_vertical_margin"</span>
<span class="hljs-attribute">tools:context</span>=<span class="hljs-value">".MainActivity"</span> ></span>

<span class="hljs-tag"><<span class="hljs-title">ListView
</span> <span class="hljs-attribute">android:id</span>=<span class="hljs-value">"@+id/listview"</span>
<span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"match_parent"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span> ></span>
<span class="hljs-tag"></<span class="hljs-title">ListView</span>></span>

<span class="hljs-tag"></<span class="hljs-title">RelativeLayout</span>></span></code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

item.xml

<code class="hljs xml has-numbering"><span class="hljs-pi"><?xml version="1.0" encoding="utf-8"?></span>
<span class="hljs-tag"><<span class="hljs-title">LinearLayout</span> <span class="hljs-attribute">xmlns:android</span>=<span class="hljs-value">"http://schemas.android.com/apk/res/android"</span>
<span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"match_parent"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"match_parent"</span>
<span class="hljs-attribute">android:orientation</span>=<span class="hljs-value">"vertical"</span>
<span class="hljs-attribute">android:padding</span>=<span class="hljs-value">"5dip"</span> ></span>

<span class="hljs-tag"><<span class="hljs-title">LinearLayout
</span> <span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"fill_parent"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:orientation</span>=<span class="hljs-value">"horizontal"</span> ></span>

<span class="hljs-tag"><<span class="hljs-title">TextView
</span> <span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:text</span>=<span class="hljs-value">"姓名:"</span>
<span class="hljs-attribute">android:textSize</span>=<span class="hljs-value">"20sp"</span> /></span>

<span class="hljs-tag"><<span class="hljs-title">TextView
</span> <span class="hljs-attribute">android:id</span>=<span class="hljs-value">"@+id/name"</span>
<span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:text</span>=<span class="hljs-value">""</span>
<span class="hljs-attribute">android:textSize</span>=<span class="hljs-value">"18sp"</span> /></span>
<span class="hljs-tag"></<span class="hljs-title">LinearLayout</span>></span>

<span class="hljs-tag"><<span class="hljs-title">LinearLayout
</span> <span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"fill_parent"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:orientation</span>=<span class="hljs-value">"horizontal"</span> ></span>

<span class="hljs-tag"><<span class="hljs-title">TextView
</span> <span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:text</span>=<span class="hljs-value">"照片:"</span>
<span class="hljs-attribute">android:textSize</span>=<span class="hljs-value">"20sp"</span> /></span>

<span class="hljs-tag"><<span class="hljs-title">TextView
</span> <span class="hljs-attribute">android:id</span>=<span class="hljs-value">"@+id/photo"</span>
<span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"wrap_content"</span>
<span class="hljs-attribute">android:text</span>=<span class="hljs-value">""</span>
<span class="hljs-attribute">android:textSize</span>=<span class="hljs-value">"18sp"</span> /></span>
<span class="hljs-tag"></<span class="hljs-title">LinearLayout</span>></span>

<span class="hljs-tag"></<span class="hljs-title">LinearLayout</span>></span></code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

1.MainActivity.java

<code class="hljs java has-numbering"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Activity</span> {</span>

<span class="hljs-keyword">private</span> String data;
<span class="hljs-keyword">private</span> Gson gson;
<span class="hljs-keyword">private</span> Root root;
<span class="hljs-keyword">private</span> A a;
<span class="hljs-keyword">private</span> B b;
<span class="hljs-keyword">private</span> ListView mListView;
<span class="hljs-keyword">private</span> List<Map<String, Object>> oList;
<span class="hljs-keyword">private</span> List<Map<String, Object>> oList2;

<span class="hljs-annotation">@Override</span>
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onCreate</span>(Bundle savedInstanceState) {
<span class="hljs-keyword">super</span>.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listview);
gson = <span class="hljs-keyword">new</span> Gson();
a = <span class="hljs-keyword">new</span> A();
b = <span class="hljs-keyword">new</span> B();
root = <span class="hljs-keyword">new</span> Root();
<span class="hljs-keyword">try</span> {
InputStream is = getResources().getAssets().open(<span class="hljs-string">"text.txt"</span>);
<span class="hljs-keyword">byte</span>[] b = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[is.available()];
is.read(b);
data = <span class="hljs-keyword">new</span> String(b);
analysisData(data);
} <span class="hljs-keyword">catch</span> (Exception e) {
<span class="hljs-comment">// TODO Auto-generated catch block</span>
e.printStackTrace();
}
}

<span class="hljs-comment">/*
* 解析数据
*/</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">analysisData</span>(String data) {
<span class="hljs-keyword">try</span> {
<span class="hljs-comment">// Type listType = new TypeToken<List<Root>>() {</span>
<span class="hljs-comment">// }.getType();</span>
oList = <span class="hljs-keyword">new</span> ArrayList<Map<String, Object>>();
List<Root> appinfos = <span class="hljs-keyword">new</span> ArrayList<Root>();
Root depts = gson.fromJson(data, Root.class);
appinfos.add(depts);

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < appinfos.size(); i++) {

root = appinfos.get(i);
List<A> listA = <span class="hljs-keyword">new</span> ArrayList<A>();
List<B> listB = <span class="hljs-keyword">new</span> ArrayList<B>();

listA = root.getA();
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> j = <span class="hljs-number">0</span>; j < listA.size(); j++) {
Map<String, Object> map = <span class="hljs-keyword">new</span> HashMap<String, Object>();
a = listA.get(j);

map.put(<span class="hljs-string">"name"</span>, a.getName());
map.put(<span class="hljs-string">"photo"</span>, a.getPhoto());
oList.add(map);
}
listB = root.getB();
oList2 = <span class="hljs-keyword">new</span> ArrayList<Map<String, Object>>();
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> j = <span class="hljs-number">0</span>; j < listB.size(); j++) {
Map<String, Object> map = <span class="hljs-keyword">new</span> HashMap<String, Object>();
b = listB.get(j);

map.put(<span class="hljs-string">"name"</span>, b.getName());
map.put(<span class="hljs-string">"photo"</span>, b.getPhoto());
oList2.add(map);
}
oList.addAll(oList2);

}

mListView.setAdapter(<span class="hljs-keyword">new</span> MyAdapter(oList, <span class="hljs-keyword">this</span>));

} <span class="hljs-keyword">catch</span> (Exception e) {
e.printStackTrace();
}

}
}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

实体类的代码如下:
A.java

<code class="hljs cs has-numbering"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> A {
<span class="hljs-keyword">private</span> String numid;

<span class="hljs-keyword">private</span> String name;

<span class="hljs-keyword">private</span> String abbreviation;

<span class="hljs-keyword">private</span> String photo;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setNumid</span>(String numid) {
<span class="hljs-keyword">this</span>.numid = numid;
}

<span class="hljs-keyword">public</span> String <span class="hljs-title">getNumid</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.numid;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span>(String name) {
<span class="hljs-keyword">this</span>.name = name;
}

<span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.name;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAbbreviation</span>(String abbreviation) {
<span class="hljs-keyword">this</span>.abbreviation = abbreviation;
}

<span class="hljs-keyword">public</span> String <span class="hljs-title">getAbbreviation</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.abbreviation;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setPhoto</span>(String photo) {
<span class="hljs-keyword">this</span>.photo = photo;
}

<span class="hljs-keyword">public</span> String <span class="hljs-title">getPhoto</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.photo;
}

}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

B、C、D的跟A一样,就不再赘述了。

还有一个Roor.java:

<code class="hljs cs has-numbering"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> Root {
<span class="hljs-keyword">private</span> List<A> a;

<span class="hljs-keyword">private</span> List<B> b;

<span class="hljs-keyword">private</span> List<C> c;

<span class="hljs-keyword">private</span> List<D> d;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setA</span>(List<A> a) {
<span class="hljs-keyword">this</span>.a = a;
}

<span class="hljs-keyword">public</span> List<A> <span class="hljs-title">getA</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.a;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setB</span>(List<B> b) {
<span class="hljs-keyword">this</span>.b = b;
}

<span class="hljs-keyword">public</span> List<B> <span class="hljs-title">getB</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.b;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setC</span>(List<C> c) {
<span class="hljs-keyword">this</span>.c = c;
}

<span class="hljs-keyword">public</span> List<C> <span class="hljs-title">getC</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.c;
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setD</span>(List<D> d) {
<span class="hljs-keyword">this</span>.d = d;
}

<span class="hljs-keyword">public</span> List<D> <span class="hljs-title">getD</span>() {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.d;
}

}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

适配器代码:MAdapter.java

<code class="hljs java has-numbering"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyAdapter</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">BaseAdapter</span> {</span>

<span class="hljs-keyword">private</span> List<Map<String, Object>> roots;

<span class="hljs-keyword">private</span> Context mContext;

<span class="hljs-keyword">private</span> LayoutInflater inflater;

<span class="hljs-keyword">private</span> Root root;

<span class="hljs-keyword">public</span> <span class="hljs-title">MyAdapter</span>(List<Map<String, Object>> roots, Context mContext) {
<span class="hljs-keyword">this</span>.roots = roots;
<span class="hljs-keyword">this</span>.mContext = mContext;
inflater = LayoutInflater.from(mContext);
}

<span class="hljs-annotation">@Override</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getCount</span>() {
<span class="hljs-keyword">return</span> roots.size();
}

<span class="hljs-annotation">@Override</span>
<span class="hljs-keyword">public</span> Object <span class="hljs-title">getItem</span>(<span class="hljs-keyword">int</span> position) {
<span class="hljs-keyword">return</span> roots.get(position);
}

<span class="hljs-annotation">@Override</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">long</span> <span class="hljs-title">getItemId</span>(<span class="hljs-keyword">int</span> position) {
<span class="hljs-keyword">return</span> position;
}

<span class="hljs-annotation">@Override</span>
<span class="hljs-keyword">public</span> View <span class="hljs-title">getView</span>(<span class="hljs-keyword">int</span> position, View convertView, ViewGroup parent) {
viewHonder honder = <span class="hljs-keyword">null</span>;
<span class="hljs-keyword">if</span> (convertView == <span class="hljs-keyword">null</span>) {
convertView = inflater.inflate(R.layout.item, <span class="hljs-keyword">null</span>);
honder = <span class="hljs-keyword">new</span> viewHonder();
honder.mName = (TextView) convertView.findViewById(R.id.name);
honder.mPhoto = (TextView) convertView.findViewById(R.id.photo);
convertView.setTag(honder);
} <span class="hljs-keyword">else</span> {
honder = (viewHonder) convertView.getTag();
}
Map<String, Object> map = <span class="hljs-keyword">new</span> HashMap<String, Object>();
map = roots.get(position);
honder.mName.setText(map.get(<span class="hljs-string">"name"</span>) + <span class="hljs-string">""</span>);
honder.mPhoto.setText(map.get(<span class="hljs-string">"photo"</span>) + <span class="hljs-string">""</span>);
<span class="hljs-keyword">return</span> convertView;
}

class viewHonder {
TextView mName;
TextView mPhoto;

}

}</code><ul class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li></ul><div class="save_code tracking-ad" style="display: none;" data-mod="popu_249"><a target=_blank target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png" alt="" /></a></div>

好了。这时候已经可以实现这个功能了。