Home  >  Q&A  >  body text

jsonObject.has()是干嘛的?

jsonObject.has()是干嘛的?

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

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


        } catch (JSONException e) {
            e.printStackTrace();
        }


高洛峰高洛峰2834 days ago1063

reply all(2)I'll reply

  • 三叔

    三叔2016-11-10 15:19:24

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

    reply
    0
  • 欧阳克

    欧阳克2016-11-10 15:18:56

    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();
        }

    可以看出是通过使用Map.containsKey(key)方法来做出判断的。

    reply
    0
  • Cancelreply