You need to sign in to do that
Don't have an account?
George Laird 29
Help with simple JSON results
Hello. I am getting a very simple JSON response back but can't seem to deseralize it correctly to get the ID that I need. The response looks like this:
{
"duration": 0.024,
"success": true,
"error_message": null,
"status_code": 201,
"payload": {
"id": "XXXXXXXXXXXXXXX",
"name": "test4204201112"
}
}
My apex looks like this:
if(res.getStatusCode() < 300){
Type resultType = Type.forName('ResponseModel');
ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);
}
}
public class ResponseModel{
public decimal duration;
public boolean success;
public string error_message;
public integer status_code;
public string payload;
public list<string> id;
public list<string> Name;
}
Of course this doesn't work. I think the whole list thing is wrong. Since payload is a JSON object, I'm having trouble getting that ID out of it. All I need is that ID. Can anyone help and change my code so that it works?
I've also tried making another class for payload and deseralize it again to there, but no luck.
{
"duration": 0.024,
"success": true,
"error_message": null,
"status_code": 201,
"payload": {
"id": "XXXXXXXXXXXXXXX",
"name": "test4204201112"
}
}
My apex looks like this:
if(res.getStatusCode() < 300){
Type resultType = Type.forName('ResponseModel');
ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);
}
}
public class ResponseModel{
public decimal duration;
public boolean success;
public string error_message;
public integer status_code;
public string payload;
public list<string> id;
public list<string> Name;
}
Of course this doesn't work. I think the whole list thing is wrong. Since payload is a JSON object, I'm having trouble getting that ID out of it. All I need is that ID. Can anyone help and change my code so that it works?
I've also tried making another class for payload and deseralize it again to there, but no luck.
Redefine your classes as shown above. The deserialization should work
All Answers
Redefine your classes as shown above. The deserialization should work