搜索

首页  >  问答  >  正文

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();
        }
高洛峰高洛峰2889 天前582

全部回复(4)我来回复

  • 怪我咯

    怪我咯2017-04-18 09:19:18

    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)方法来做出判断的。

    回复
    0
  • PHP中文网

    PHP中文网2017-04-18 09:19:18

    回复
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:19:18

    判断类中是否有某个字段

    回复
    0
  • 怪我咯

    怪我咯2017-04-18 09:19:18

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

    回复
    0
  • 取消回复