jsonObject.has()是干嘛的?

jsonObject.has()是干嘛的?


  String jsonStr=new String(data);

        try {

            JSONObject jsonObject=new JSONObject(jsonStr);


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

            }



        } catch (JSONException e) {

            e.printStackTrace();

        }


翻过高山走不出你
浏览 3291回答 4
4回答

倚天杖

Determine if the JSONObject contains a specific key.Parameters:key A key string.Returns:true if the key exists in the JSONObject.&nbsp; &nbsp; public boolean has(String key) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return this.map.containsKey(key);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; public JSONObject() {&nbsp; &nbsp; &nbsp; &nbsp; this.map = new HashMap<String, Object>();&nbsp; &nbsp; }可以看出是通过使用Map.containsKey(key)方法来做出判断的。

慕标琳琳

茅侃侃

判断类中是否有某个字段

慕田峪7331174

查询对象是否包含该key,返回boolean,与Map.containsKey(key)用法一致
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java