There is a JSON that gives the server, I am confused by the property, inside the properties , especially the values ​​of @key , @value , how to properly parse these properties ?

enter image description here

until properties were just a string, everything was simple:

there was a class User :

 public class User { @SerializedName("username") String username; @SerializedName("name") String name; @SerializedName("email") String email; @SerializedName("properties") String properties; public User(String username, String name, String email, String properties) { this.username = username; this.name = name; this.email = email; this.properties = properties; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getProperties() { return properties; } public void setProperties(String properties) { this.properties = properties; } @Override public String toString() { return username + " (" + name + ")"; } } 

Interface with API:

 public interface MessengerApi { @GET("users") Observable<List<User>> users(@Header("Authorization") String auth, @Header("Content-type") String contentType, @Header("Accept") String accept); } 

The method in which I get the data:

 private void getUsers() { String credentials = "admin" + ":" + "admin"; final String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); String contentType = "application/json"; String accept = "application/json"; Subscription subscription = App.service.users(basic, contentType, accept) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(users -> { Log.e("Users", users.toString()); contacts.addAll(users); for (int i = 0; i < contacts.size(); i++) { Log.e("Users in allUsers", String.valueOf(contacts.get(i))); } contactAdapter.notifyDataSetChanged(); }, throwable -> { }); addSubscription(subscription); } 

    2 answers 2

    try this

     public class User { @SerializedName("properties") private Properties properties; ... } public class Properties { @SerializedName("property") private Property property; ... } public class Property { @SerializedName("@key") private String key; @SerializedName("@value") private String value; ... } 

      Added another class Users:

       public class Users { @SerializedName("user") List<User> user; // getters and setters } 

      And:

       public class User { @SerializedName("properties") private Properties properties; ... } public class Properties { @SerializedName("property") private Property property; ... } public class Property { @SerializedName("@key") private String key; @SerializedName("@value") private String value; ... }