java - jsonObject.has()是干嘛的?
高洛峰
高洛峰 2017-04-18 09:17:18
0
4
576

jsonObject.has()是干嘛的?

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

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


        } catch (JSONException e) {
            e.printStackTrace();
        }
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

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

It can be seen that the judgment is made by using the Map.containsKey(key) method.

洪涛

巴扎黑

Determine whether there is a certain field in the class

刘奇

Query whether the object contains the key and return boolean, which is consistent with the usage of Map.containsKey(key)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template