+ Start a Discussion
Vasavi VajinepalliVasavi Vajinepalli 

Need to fetch one field from response of http callout

Hi,

I am getting the below response from a http callout. 

{\"response\" : [{\"status\" : \"success\", \"type\" : \"success\", \"code\" : \"E0\", \"message\" : \"success\"}]}"
I need to retrieve "code" : "E0". Can anyone help me in retreiving this value?

Thanks,
vasavi 
Pramodh KumarPramodh Kumar
Hi Vasavi,

I think this is your json response, use the below class to retrieve the field.
{
    "response": [
        {
            "status": "success",
            "type": "success",
            "code": "E0",
            "message": "success"
        }
    ]
}

public class fromJSON{
    public cls_response[] response;
    class cls_response {
        public String status;    //success
        public String type;    //success
        public String code;    //E0
        public String message;    //success
    }
    public static fromJSON parse(String json){
        return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
    }    
}
Vasavi VajinepalliVasavi Vajinepalli
Hi Pramod,

Thanks for the solution. Is there any way like not to create a new class for deserializing. I mean is there any way to implement this in the same classs in which am posting the data?

thanks,
vasavi
Pramodh KumarPramodh Kumar
I dont think so. this is the simplest way of deserializing the JSON Data.


More over you can't have 2 level deep in apex class.