如何使用Retrofit解析动态JSON? [英] How to parse dynamic JSON with Retrofit?
本文介绍了如何使用Retrofit解析动态JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有动态JSON,例如: http://pastebin.com/QMWRZTrD
I have dynamic JSON, here is example: http://pastebin.com/QMWRZTrD
我该如何使用Retrofit解析它?
How I can parse it with Retrofit?
我无法生成POJO类,因为我具有诸如"5411"和"5412"之类的动态字段.
I failed to generate POJO classes, since I have dynamic fields like "5411" and "5412".
编辑:
我通过使用Map来解决它,因为第一个值始终是整数,第二个是对象列表.
I solved it by using Map, since first value is always integer, and second is list of objects.
@FormUrlEncoded
@POST("history.php")
Observable<Map<Integer, List<Vehicle>>> getHistory(@Field("uredjaji") String vehicleId, @Field("startDate") String startDATE, @Field("endDate")
推荐答案
在使用Random键的情况下,可以使用Map
对其进行序列化和反序列化.
Observable<Map<Integer, List<YourObject>>>
you can use Map
to serialize and deserialize it in case of Random keys.
Observable<Map<Integer, List<YourObject>>>
这篇关于如何使用Retrofit解析动态JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文