java - jsonObject.has()是干嘛的?
本文介绍了java - jsonObject.has()是干嘛的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
jsonObject.has()是干嘛的?
String jsonStr=new String(data);
try {
JSONObject jsonObject=new JSONObject(jsonStr);
if (jsonObject.has("fileUri")){
}
} catch (JSONException e) {
e.printStackTrace();
}
解决方案
Determine if the JSONObject contains a specific key.
Parameters:
key A key string.
Returns:
true if the key exists in the JSONObject.
public boolean has(String key) {
return this.map.containsKey(key);
}
public JSONObject() {
this.map = new HashMap<String, Object>();
}
可以看出是通过使用Map.containsKey(key)方法来做出判断的。
这篇关于java - jsonObject.has()是干嘛的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文