You need to sign in to do that
Don't have an account?
Gaurav Idnani
The snapshot shows the values in a collection obtained from a JSON response , i am unable to access the individual values for name or date.Kindly help
public class HolidayAPI {
public static void test (){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserialize the JSON string into collections of primitive data types.
Map<String,Object> hoMap = (Map<String , Object>) JSON.deserializeUntyped(response.getBody()) ;
Map<String,Object> hoList = (Map<String , Object>)hoMap.get('holidays');
List<object> temp = new List<Object> (hoList.values());
System.debug('HTTP response='+response);
System.debug('First level data(deserialied)'+hoMap);
System.debug('Second level data'+hoList);
System.debug('Third level data='+temp);
for (Object t:temp){
System.debug(t);
}
}
}}
Kindly help me understand how to access the individual field values in this collection ( code provided for reference)
The snapshot shows the values in a collection obtained from a JSON response , i am unable to access the individual values for name or date.Kindly help
public class HolidayAPI {
public static void test (){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserialize the JSON string into collections of primitive data types.
Map<String,Object> hoMap = (Map<String , Object>) JSON.deserializeUntyped(response.getBody()) ;
Map<String,Object> hoList = (Map<String , Object>)hoMap.get('holidays');
List<object> temp = new List<Object> (hoList.values());
System.debug('HTTP response='+response);
System.debug('First level data(deserialied)'+hoMap);
System.debug('Second level data'+hoList);
System.debug('Third level data='+temp);
for (Object t:temp){
System.debug(t);
}
}
}}
refer this link
http://www.salesforcenextgen.com/how-to-do-json-parsing-of-a-wrapper-class-in-salesforce/
https://developer.salesforce.com/forums/?id=9060G000000IARkQAO
when I debug the value of that object the ouput I get is
System.debug (ob);
output
({date=2017-01-01, name=New Year's Day, observed=2017-01-01, public=false})
The outermost small bracket '(' suggests this is some sort of collection as I am unable to individual attributes ie date or name
What I want to know is which collection this is and how to access the individual attributes