Using JSON2Apex (here), you can easily generate a class that you can use to deserialize your JSON.
JSON2Apex outputs code like this:
public class Outer {
public List<Ideal> ideal;
public List<Ideal> idealFiltered;
public List<Ideal> InBudget;
public class Ideal {
public String product;
public String percent;
public String dollarAmount;
}
public static Outer parse(String json) {
return (Outer) System.JSON.deserialize(json, Outer.class);
}
}
From here, you can iterate through the lists inside the main Object and extract the values as you need.
The key is the parse
method. What you need to do is pass in your string like this:
Outer myParsedResult = Outer.parse(httpCalloutResponseString);
Then you can literally go:
for (Ideal idealItem : Outer.ideal){
//do something here... maybe if a value is x, assign that value to your
//public property on your vf page etc...
}
The documentation for readValueAs says (emphasis mine):
When deserializing JSON content into an Apex class in any API version,
or into an object in API version 35.0 or later, no exception is
thrown. When no exception is thrown, this method ignores extraneous
attributes and parses the rest of the JSON content.
My reading of this is that your code should continue to work when extra JSON attributes are added. But I suggest you create a test case to ensure that the code does what the documentation says.
Best Answer
If you mean on the client side, then its just: