-
Hi. How can I use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The https://github.com/google/jsinterop-base/ project provides some tools that can help here - the simplest would be Object parsed = JSON.parse("{\"a\":\"b\"}");
JsPropertyMap<Object> contents = Js.asPropertyMap(parsed);
// Using Any lets you put in runtime checks for the property type
String value = contents.getAsAny("a").asString();
// You can also directly read the value and cast
String checked = (String) contents.get("a");
String checked2 = Js.cast(contents.get("a"));
String unchecked = Js.uncheckedCast(contents.get("a")); Rule of thumb: Java's cast is for when Java will accept this as correct and you want the type checked,
contents.forEach(key -> {
// do something with contents.get(key)
}); In https://github.com/google/elemental2/ then we also have |
Beta Was this translation helpful? Give feedback.
The https://github.com/google/jsinterop-base/ project provides some tools that can help here - the simplest would be
Js.asPropertyMap(parsed)
, which would return ajsinterop.base.JsPropertyMap<Object>
instance. This doesn't directly provide a way to read all keys, but you can query known keys asObject
or asjsinterop.base.Any
instances.