function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EmilyCobbEmilyCobb 

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:
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?
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) https://www.adminbooster.com/tool/json2apex

 
String json = httpResponseVar.getBody();
wrapperClassName wraperClassVar  = System.JSON.deserialize(json, wrapperClassName.class);


Let us know if this will help you