我为JsonObject使用以下包: http://vertx.io/docs/apidocs/io/vertx/core/json/JsonObject.html
如果我得到一个带有键' fieldName'的JsonObject。我希望得到它的价值,我必须使用' getString',' getInteger',' getArray'等功能。我的意思是我必须先了解价值的类型。如果我不知道怎么办? 是否存在从JsonObject中检索值而不知道其类型的通用函数?
答案 0 :(得分:4)
使用 getValue(String)
。
它会返回Object
,然后您可以测试类型并进行相应的转换。
评论说明:检查GitHub上的代码,看起来getField(String)
分支中存在2.x
方法。看起来getValue(String)
被委托给getField(String)
方法(see the code)。截至2017年8月,getField(String)
(see the code)中没有master
。