Quantcast
Viewing all articles
Browse latest Browse all 2

How to get dynamic JSON Value by Key without parsing to Java Object?

I am trying to get a json(has unknown template) value with a dynamic key like;

"user.specs.id"

Problem is my json structure is not static and because of this I can't parse it to a java Object or get its properties with Gson methods.

{"user": {"specs": {"id": 12222,"name": "foo"        }     }}

Is there a way to extract some data from any json with some key?

EDIT: I have a service method like;

public Object getValueByKey(String json, String key);

possible values for "json" param;

{"name": "test"}    //possible key "name"{"user": {"id": 1232}}   //possible key "user.id"{"cars": ["car1", "car2"]}   //possible key "cars[0]"

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>