You need to sign in to do that
Don't have an account?
EmilyCobb
Processing nested JSON results in Apex from wrapper class
I've created a wrapper class for my JSON structure (with json2apex). I have been able to successfully process results up to two levels deep, but this goes further:
I'm trying to get at the data in Data.Products.Options.Choices and have not had any luck.
I was expecting to be able to traverse wrapperClassVar like I normally do with one or two levels, but get compiler errors once I go to level 3 (Initial term of field expression must be a concrete SObject: List<wrapperClassName.Products>). Any suggestions?
public class Options { public String name; public String code; public List<Choices> choices; } public class Prices { public InitialPrice initialPrice; public MonthlyPrices monthlyPrices; public Integer quantity; } public class Errors { public String message; public String errorCode; public String path; } public class MonthlyPrices { public InitialPrice year1; public InitialPrice year2; public InitialPrice year3; } public class Products { public String categoryCode; public String code; public Boolean isDefault; public String name; public List<Options> options; public List<Prices> prices; } public class Choices { public String name; public String code; } public Integer statusCode; public Data data; public List<Errors> errors; public class Data { public String code; public String name; public List<Products> products; }
I'm trying to get at the data in Data.Products.Options.Choices and have not had any luck.
wrapperClassName wraperClassVar = wrapperClassName.parse(httpResponseVar.getBody());
I was expecting to be able to traverse wrapperClassVar like I normally do with one or two levels, but get compiler errors once I go to level 3 (Initial term of field expression must be a concrete SObject: List<wrapperClassName.Products>). Any suggestions?
1) https://www.adminbooster.com/tool/json2apex
Let us know if this will help you