io.vertx.core.json.JsonObject: 如何获取给定键值的类型?

io.vertx.core.json.JsonObject: How to get the type of the value for given key?

我正在为 JsonObject 使用以下包: http://vertx.io/docs/apidocs/io/vertx/core/json/JsonObject.html

如果我得到一个带有键 'fieldName' 的 JsonObject 并且我想得到它的值,我必须使用 'getString'、'getInteger'、'getArray' 等函数.我的意思是我必须事先知道值的类型。如果我不知道会怎样? 是否有任何在不知道其类型的情况下从 JsonObject 检索值的通用函数?

使用 getValue(String)

它 returns 一个 Object 然后你可以测试类型并相应地转换。


注释注释: 检查 GitHub 上的代码,看起来 getField(String) 方法存在于 2.x 分支。看起来 getValue(String) 被委托给 getField(String) 方法 (see the code). As of August 2017, there's no getField(String) in the master (see the code).