+ Start a Discussion
Flight PlanFlight Plan 

How to deserialize the JSON response with dynamic data ????

Hi All,


I am using JSON.deserialize(JSONResponse, Sample.class) method for parsing

Below is the sample

public class Sample{

    public String a {get;set;}
    public String b {get;set;}
    public String c {get;set;}
    public String d {get;set;}
    public Sample1 test {get;set;}
    
    
    
    
    public Sample1{ // in response, for this class dont know about the fields. in each and every response the fields are changing.
    }
    
    
}


How to handle such response using JSON.deserialize  and store it in Apex class variable?

Response :- 1
{
     "a": "Sometext",
      "b": "Sometext",
       "c": "Sometext",
        "d": "Sometext",
      "test": {
        "Data1": {
          "score": 2
        },
        "Data2": {
          "score1": 1
        },
        "Data3": {
          "score1": 2
        }
      }
 
 }
 
 Response :- 2
 {
     "a": "Sometext",
      "b": "Sometext",
       "c": "Sometext",
        "d": "Sometext",
      "test": {
        "Data50": {
          "score12": 2
        }       
      }
}

Any pointer's on this would be highly appricate.
Thanks in Advance.

 

 

code developercode developer

I am facing the same problem.Have you find any solution?