java - How to find a key in a JSON file with Gson library? -


given json file looks code below, how can find specific key corresponding value without hard-coding structure in java class or otherwise. let's want "signal_settings" json object given possibility of changes in json file structure want object regardless example iterating through keys in file. have tried iteratively , failed, think recursive function way didn't find solution yet. iterative code looks this:

while (true) {             try {                 for(map.entry<string, jsonelement> entry:newjsonobj.entryset()){                     system.out.println(entry.getkey());                     system.out.println("before newjsonobj:" + newjsonobj);                     newjsonobj = newjsonobj.getasjsonobject(entry.getkey());                     system.out.println("after newjsonobj:" + newjsonobj + "\n");                      //tempentryset = newjsonobj.entryset().iterator().next();                 }                  //system.out.println("key:" + tempentryset.getkey());                  //system.out.println("tempentry:" + tempentryset);             }catch (exception e){                 break;             }         } 

and json file:

{     "config2": {         "udp_settings": {             "listenaddress": "'127.0.0.1'",             "listenport": "54523"         },         "signal_settings": {             "count": 1,             "signals": [                 {                     "name": "time",                     "type": "uint8",                     "interval": "foo",                     "description": "",                     "unit": null                 },                 {                     "name": "othersignal",                     "type": "uint8",                     "interval": "fff",                     "description": "",                     "unit": null                 }             ]         },         "tag_settings": null,         "model_settings": null     } } 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -