在Java中,我知道您可以检查isNull()方法是否存在密钥.有没有办法检查密钥包含哪种数据?
请考虑以下示例.
我想要一个像JSONBody.getDataType("key")这样的函数,它会返回String
{
"key" : "value"
}
Run Code Online (Sandbox Code Playgroud)
我想要一个像JSONBody.getDataType("key")这样的函数,它会返回JSONObject
{
"key" : {
"parm1" : "value1",
"parm2" : "value2"
}
}
Run Code Online (Sandbox Code Playgroud)
我想要一个像JSONBody.getDataType("key")这样的函数,它会返回JSONArray
{
"key" : [
"value1",
"value2",
"value3"
]
}
Run Code Online (Sandbox Code Playgroud)
我想要一个像JSONBody.getDataType("key")这样的函数,它会返回布尔值
{
"key" : true
}
Run Code Online (Sandbox Code Playgroud)
这样的事情存在吗?
JSONObject stuff = new JSONObject(whatever);
Object thing = stuff.get("key");
String classNameOfThing = thing.getClass().getName();
Systen.out.println("thing is a " + classNameOfThing);
if (thing instanceof Integer) {
System.out.println("thing is an Integer");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8944 次 |
| 最近记录: |