You need to sign in to do that
Don't have an account?

Access values in JSON Parser class
I have this JSON parser class:
public class GoogleAPIParser {
public class Address_components {
public String long_name;
public String short_name;
public List<String> types;
}
public List<Results> results;
public String status;
public class Location {
public Double lat;
public Double lng;
}
public class Geometry {
public Location location;
public String location_type;
public Viewport viewport;
}
public class Results {
public List<Address_components> address_components;
public String formatted_address;
public Geometry geometry;
public List<String> types;
}
public class Viewport {
public Location northeast;
public Location southwest;
}
public static GoogleAPIParser parse(String json) {
return (GoogleAPIParser) System.JSON.deserialize(json, GoogleAPIParser.class);
}
}
Which I invoke using:
GoogleAPIParser parser = GoogleAPIParser.parse(jsonResponse);
How do I go through and access those attributes within the class that is returned now?
Be careful with access to inner properties. Some of them can be equal to null.
All Answers
jsonResponse = 'GoogleAPIParser[' + jsonResponse + ']';
And, when you call your deserialization, it should (if the variable names and structure match the HTTP service you're consuming) parse your individual elements into the structure you defined.
Don't forget your setter;getter methods too.
Be careful with access to inner properties. Some of them can be equal to null.