Gson Parse Json with array with different object types

后端 未结 5 1368
梦毁少年i
梦毁少年i 2020-12-09 10:16

How can I parse this JSON using Gson? I have an array with multiple object types and I don\'t know what kind of object I need to create to save this structure. I cannot cha

5条回答
  •  孤城傲影
    2020-12-09 10:25

    I think this link might help you: https://sites.google.com/site/gson/gson-user-guide#TOC-Collections-Examples

    Basically, create a class for your "object" (kind of user I guess), and then use the deserialization code of Gson, like this:

    Type collectionType = new TypeToken>(){}.getType();
    Collection users= gson.fromJson(json, collectionType);
    

提交回复
热议问题