繁体   English   中英

如何使用Retrofit从JSON对象获取密钥?

[英]How can i get Key from JSON Object using Retrofit?

我想从json对象获取密钥。 有什么办法可以通过改装轻松获得密钥吗?在这里,我声明了我的pojo模型存在不同的密钥1)uid 2)名称

public class Account {

        @SerializedName("uid")
        @Expose
        private String uid;
        @SerializedName("name")
        @Expose
        private String name;

        /**
         * @return The uid
         */
        public String getUid() {
            return uid;
        }

        /**
         * @param uid The uid
         */
        public void setUid(String uid) {
            this.uid = uid;
        }

        /**
         * @return The name
         */
        public String getName() {
            return name;
        }

        /**
         * @param name The name
         */
        public void setName(String name) {
            this.name = name;
        }

}

公共接口JsonObject扩展了JsonStructure,Map。因此,JSONObject是一个Map,其键的类型为String,其值的类型为JSONValue。

而且Map.keySet()的javadoc说:

设置keySet()

返回此映射中包含的键的Set视图。因此,JSONObject.keySet()返回的是一个Set(这很合逻辑,因为JSON对象的键是字符串)。 所以你要:

设置键= posts.keyset();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM