While playing with the JSON parser I encountered a use case (described below in detail) for which using JSON.deserialize(JSONResponse, SampleParent.class) method for parsing doesn't work.
Below is the use case:
public class SampleParent{
public String a {get;set;}
public String b {get;set;}
public String c {get;set;}
public String d {get;set;}
public SampleChild test {get;set;}
public SampleChild{
// in response, for this class doesn't know about the fields. in each and
// every response the fields are changing i.e. it is dynamic with no structure
}
}
How to handle such response using JSON.deserialize and store it in Apex class variable?
Actually I want to store such response in String 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
}
}
}
Actually I want to store such response in String variable like a = '{ "Data50": {"score12": 2}}'
Can we handle this use case in Salesforce ?
Any pointers on this would be highly appreciated. Thanks in Advance.