jsonObject.has()是干嘛的?

jsonObject.has()是干嘛的?

  String jsonStr=new String(data);
        try {
            JSONObject jsonObject=new JSONObject(jsonStr);

            if (jsonObject.has("fileUri")){
            }


        } catch (JSONException e) {
            e.printStackTrace();
        }
阅读 27.2k
4 个回答
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)方法来做出判断的。

判断类中是否有某个字段

查询对象是否包含该key,返回boolean,与Map.containsKey(key)用法一致

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题