用Gson则样解析这类型的json

79043076 发布于 2016/02/19 11:05
阅读 2K+
收藏 0
[{"id":1,"district":"XinCheng","street":"Event Street","lat":34.265579775147,"lng":108.95783711025,"full_address":"East Street Roma Load  #123","location":"骡马市"},{"id":2,"district":"YanTa","street":"ChangAn Street","lat":34.242485194491,"lng":108.95358075909,"full_address":"Yanta ChangAn Street  #108","location":"长安街"},{"id":3,"district":"BeiLin","street":"BellTower","lat":34.265128013749,"lng":108.95376509138,"full_address":"Bell Tower  #1","location":"钟楼商圈"},{"id":4,"district":"BeiLin","street":"Huan Cheng Nan Lu","lat":34.256792774195,"lng":108.94321242706,"full_address":"Huan Cheng Nan Lu #234","location":"南二环"},{"id":5,"district":"XinCheng","street":"WuLuKou","lat":34.258739483934,"lng":108.98897427061,"full_address":"WuLuKou WanDa#5","location":"五路口"},{"id":6,"district":"PaQiao","street":"Qing Long Street","lat":34.293402831234,"lng":108.91345709873,"full_address":"Qing Long Street #4","location":"小寨商圈"},{"id":7,"district":"YanTa","street":"NanShaoMen","lat":34.228711483934,"lng":108.92894527061,"full_address":"NanShaoMen #56","location":"立丰国际"},{"id":8,"district":"GaoXin","street":"GaoXinRoad","lat":34.253403331234,"lng":108.97345723463,"full_address":"GaoXinRoad 28#","location":"世纪金花"}]
加载中
0
柏show
柏show
String json = "[{\"aaa\":123,\"bbb\":456},{\"aaa\":789,\"bbb\":987}]";//json串        
Gson gson = new Gson();
List<Object> list = gson.fromJson(json, List.class);




7
79043076
回复 @柏show : 谢谢以解决
柏show
柏show
回复 @79043076 : 按理说list.get(0)就能取到一个Air的实例,再用Air.getXXX()方法就能取到值了,实在不行你就List<Map> list = gson.formJson(json,List.class);String id = list.get(0).get("id");
7
79043076
回复 @79043076 : 我用list.get(0)打出来是这样的引号都没了 {id=1.0, district=XinCheng, street=Event Street, lat=34.265579775147, lng=108.95783711025, full_address=East Street Roma Load #123, location=骡马市}
7
79043076
回复 @柏show : list.size()有值就是取不出来具体的值。
柏show
柏show
回复 @79043076 : list.get(0)取不到数据么?你打下断点看看,或者直接输出list.get(0)
下一页
0
rabbitgg
rabbitgg
数据都没给全?
0
7
79043076
json 是这样的[{"id":1,"district":"XinCheng","street":"Event Street","lat":34.265579775147,"lng":108.95783711025,"full_address":"East Street Roma Load  #123","location":"骡马市"},
{"id":2,"district":"YanTa","street":"ChangAn Street","lat":34.242485194491,"lng":108.95358075909,"full_address":"Yanta ChangAn Street  #108","location":"长安街"},

{"id":3,"district":"BeiLin","street":"BellTower","lat":34.265128013749,"lng":108.95376509138,"full_address":"Bell Tower  #1","location":"钟楼商圈"}]

则么用Gson解析?


0
wenshao
wenshao
推荐你用阿里巴巴的开源组件fastjson,单一jar,无依赖,速度更快,功能更强,更好用。 https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98
返回顶部
顶部