Gson Parse Json with array with different object types

后端 未结 5 1365
梦毁少年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:41

    You can create corresponding java classes for the json objects. The integer, string values can be mapped as is. Json can be parsed like this-

    Gson gson = new GsonBuilder().create();
    Response r = gson.fromJson(jsonString, Response.class);
    

    Here is an example- http://rowsandcolumns.blogspot.com/2013/02/url-encode-http-get-solr-request-and.html

提交回复
热议问题