I am getting a json response from a server with three fix json object field and one field with different json objects.
Example - Response 1
{
status : "success",
error-code : "",
message : "login successful",
data : {
token : "token value",
refresh-token : "refresh token value"
}
}
Example - Response 2
{
status : "success",
error-code : "",
message : "user data fetched",
data : {
first-name: "josh",
last-name : "walter",
age : "30",
phone: 1234567890,
address : "x street, dc"
}
}
for above json response created struct as follows
type loginData struct {
Token string `json:"token"`
RefreshToken string `json:"refresh-token"`
}
type userdata {
FirstName string `json:"first-name"`
LastName string `json:"refresh-token"`
Age string `json:"age"`
Phone string `json:"phone"`
Address string `json:"address"`
}
type response struct {
Status string `json:"status"`
ErrorCode string `json:"error-code"`
RespMessage string `json:"message"`
RespData string `json:"data"`
}
How to add logindata struct while unmarshaling during login response and userdata struct while unmarshaling userdata response in "RespData" field in response struct