Saturday, 15 August 2015

java - Getting a value from deep inside JSON -



java - Getting a value from deep inside JSON -

i connecting 3rd party api , getting long json string. need 1 value it, located pretty deep within hierarchy. there simple way it, without going through whole thing? looked on nil seems easy.

here's example:

"response":{"status":1,"httpstatus":200,"data":{"mydesiredinfo":"someinfo"},"errors":[],"errormessage":null}}

i've been trying utilize gson can blob jsonobject. sure there's simple, this:

jsonobject.get("mydesiredinfo")

or @ minimum this:

jsonobject.get("response.data.mydesiredinfo")

but doesn't seem exist.

so there parser out there allow me this?

this json string

string s="{"age":0,"name":"name","email":"emailk","address":{"housename":"villa"}}";

i utilize next code housename

jsonelement je = new jsonparser().parse(s); jsonobject asjsonobject = je.getasjsonobject(); jsonelement = asjsonobject.get("address"); system.out.println(s + "\n" + get); jsonobject asjsonobject1 = get.getasjsonobject(); jsonelement get1 = asjsonobject1.get("housename"); system.out.println(get1);

the next output :

{"age":0,"name":"name","email":"emailk","address":{"housename":"villa"}} {"housename":"villa"} "villa"

i don't think there way this. tried in other ways didn't output.

java json gson

No comments:

Post a Comment