简体   繁体   中英

Android Retrofit Json Parsing(part of json dynamic)

We are using Retrofit 1.9

Initially server was returning a json like this-

{
"known_key1":"value1",
"known_key2":"value2"
}

We had created Model -

public class ResponseModel {
    @SerializedName("known_key1")
    private String knownKey1;

    @SerializedName("known_key2")
    private String knownKey2;
} 

Everything was working fine.

but now server is returning some more keys in the response, but the keys are dynamic -

{
"known_key1":"value1",
"known_key2":"value2",
"dynamic_key1":"value1",
"dynamic_key2":"value2"
}

Now what should be our Model ?

对于这种情况,您可以使用地图

Map<String, Object> map

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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