java - Gson.fromJson, how to use dynamic json value on my POJO class? -


gson class:

import com.google.gson.*; 

myjson:

{ "time": "notime", "query": {      "pages": {          "18302": {              "title": "car",              "pagelanguage": "en"          }       } } } 

custom pojo class:

public class myclass {     public string time;     public query query;      public class query {         public ? pages;          //...     } } 

java code:

gson gson = new gsonbuilder().create(); myclass data = gson.fromjson(myjson, myclass.class); 

what class should set "pages" variable handle dynamically changing (for exp: "18302") json key?

you use map.

public class myclass {     public string time;     public query query;      public static class query {         public map<string, page> pages; // <-- here          public static class page {             public string title;             public string pagelanguage;         }     } } 

"18302": {...} stored entry in map key being "18302" , value being new page object.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -