I have a JsonObject for example
JsonObject jsonObject = {"keyInt":2,"keyString":"val1","id":"0123456"}
Each JSONObject contains an "id" entry, but the number of other key / value pairs is NOT defined, so I want to create an object with two attributes:
class myGenericObject { Map<String, Object> attributes; String id; }
So, I want my attribute map to look like this:
"keyInt" -> 4711 "keyStr" -> "val1"
I found this solution
Map<String, Object> attributes = new HashMap<String, Object>(); Set<Entry<String, JsonElement>> entrySet = jsonObject.entrySet(); for(Map.Entry<String,JsonElement> entry : entrySet){ attributes.put(entry.getKey(), jsonObject.get(entry.getKey())); }
but the values ββare enclosed in ""
"keyInt" -> "4711" "keyStr" -> ""val1""
How to get simple values ββ(4711 and "val1")?
Input data:
{ "id": 0815, "a": "a string", "b": 123.4, "c": { "a": 1, "b": true, "c": ["a", "b", "c"] } }
or
{ "id": 4711, "x": false, "y": "y?", }