I think I am just missing something simple - using very simplified and generic code for example.
I have some JSON:
{
"level1":[
{
"level2":{
"id":119,
"createdAt":"2024-05-06T17:36:32.533Z",
"user":{
"id":1,
"firstName":"First",
"lastName":"Name",
"email":"[email protected]",
"emailUnsubscribed":"false"
},
"organization":"Acme",
"details":[
{
"d1":{
"ref":"ref1",
"name":"BetterName",
"moreDetails":[
{
"detail1":{
"name":"smith",
"random":"123123123"
}
}
]
}
},
{
"d1":{
"ref":"reg2",
"name":"Name2",
"moreDetails":[
{
"detail1":{
"name":"ccg",
"random":"333444555"
}
},
{
"detail1":{
"name":"acg",
"random":"555666777"
}
}
]
}
}
]
}
}
]
}
That I use a Wrapper class to parse:
public class fromJSON{
public cls_level1[] level1;
class cls_level1 {
public cls_level2 level2;
}
class cls_level2 {
public Integer id;
public String createdAt;
public cls_user user;
public String organization;
public cls_details[] details;
}
class cls_user {
public Integer id;
public String firstName;
public String lastName;
public String email;
public String emailUnsubscribed;
}
class cls_details {
public cls_d1 d1;
}
class cls_d1 {
public String ref;
public String name;
public cls_moreDetails[] moreDetails;
}
class cls_moreDetails {
public cls_detail1 detail1;
}
class cls_detail1 {
public String name;
public String random;
}
public static fromJSON parse(String json){
return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
}
}
But when I do something like:
fromJSON testWrapper = fromJSON.parse(json);
System.debug(testWrapper.level1);
|DEBUG|(cls_level1:[level2=cls_level2:[createdAt=2024-05-06T17:36:32.533Z, details=(cls_details:[d1=cls_d1:[moreDetails=(cls_moreDetails:[detail1=cls_detail1:[name=smith, random=123123123]]), name=BetterName, ref=ref1]], cls_details:[d1=cls_d1:[moreDetails=(cls_moreDetails:[detail1=cls
I can see the data, but cannot access it.
System.debug(testWrapper.level1.level2)
Variable does not exist: level2
Not sure what I am missing or forgetting.
Thanks in Advance!