You need to sign in to do that
Don't have an account?
Unexpected token 'Map'. at line 32 column 12
Unexpected token 'Map'. at line 32 column 12
===================================
public with sharing class AccountWeatherController {
public String city {get;set;}
public String temp {get;set;}
public String pressure {get;set;}
public String humidity {get;set;}
public String temp_min {get;set;}
public String temp_max {get;set;}
public AccountWeatherController(ApexPages.StandardController stdController) {
Account account = (Account)stdController.getRecord();
account = [SELECT Id, ShippingCity FROM Account WHERE Id =:account.Id];
String accountCity = account.ShippingCity;
String apiKey = 'XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX';
String requestEndpoint = 'http://api.openweathermap.org/data/2.5/weather';
requestEndpoint += '?q=' + accountCity;
requestEndpoint += '&units=metric';
requestEndpoint += '&APPID=' + apiKey;
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(requestEndpoint);
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 results = (Map) JSON.deserializeUntyped(response.getBody());
city = String.valueOf(results.get('name'));
Map mainResults = (Map)(results.get('main'));
temp = String.valueOf(mainResults.get('temp'));
pressure = String.valueOf(mainResults.get('pressure'));
humidity = String.valueOf(mainResults.get('humidity'));
temp_min = String.valueOf(mainResults.get('temp_min'));
temp_max = String.valueOf(mainResults.get('temp_max'));
} else {
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'There was an error retrieving the weather information.');
ApexPages.addMessage(myMsg);
}
}
}
next to the comments (// Deserialize the JSON string into collections of primitive data types.)
the lines having Map are throwing the above error as "Unexpected token 'Map'. at line 32 column 12"
It would be great to solve the above issue....thanks a lot
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm
- http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/