Answer the question
In order to leave comments, you need to log in
How to parse a double JsonObject in Retrofit?
Using the Retrofit library, process the response from the server, which looks like this
{"token":"WFRHaUlzM0t1dlc1T1N6dkdpNlZIQlZ1RXV3c0l2dGwyc2NFN0RsU3pTbDdyYWpMNDJua0NqNSs2WmJKTWpJVA","errorNumber":3,"errorDescription":"invalid token","user":{"id":null,"type":0}}
import com.google.gson.annotations.SerializedName;
import org.json.JSONObject;
class TattooMarketServerInfo {
@SerializedName("token")
private String token;
@SerializedName("errorNumber")
private String errorNumber;
@SerializedName("errorDescription")
private String errorDescription;
// user fields
@SerializedName("user")
private JSONObject user;
@SerializedName("type")
private int type;
@SerializedName("id")
private String id;
@Override
public String toString() {
return "TattooMarketServerInfo:" + '\n' +
"token = " + token + '\n' +
"errorNumber = " + errorNumber + '\n' +
"errorDescription = " + errorDescription + '\n' +
"user = " + user.toString() + '\n' +
"id = " + id + '\n' +
"type = " + type + '\n';
}
}
Answer the question
In order to leave comments, you need to log in
Create a separate User class with id and type fields.
In the TattooMarketServerInfo class, the user field type must be User, not JSONObject, and the type and id fields from the TattooMarketServerInfo class must be removed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question