I have created API URL for using autocomplete functionality as I give address in text box it display the related list of addresses. I need concatenate some address fields such as city, postcode, city code it display the next textbox. Please find below my JSON file and class. can you please suggest me what should I need to changes.
global class frenchaddress {
public String accName{get;set;}
public Id accId{get;set;}
public PageReference refresh(){
return null;
}
@RemoteAction
global static List<String> restapi(string accName){
string jsonStr;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q=' + accName+ '');
req.setHeader('Accept','application/JSON');
req.setMethod('GET');
HttpResponse res = h.send(req);
system.debug('res.getBody()===>'+res.getBody().replace('\n', ''));
List<String> calOut = new List<String>();
jsonStr= res.getBody();
JSONParser parser = JSON.createParser(jsonStr);
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
String fieldName = parser.getText();
if(fieldName == 'label'){
parser.nextToken();
calOut.add(parser.getText());
}
if(fieldName == 'context'){
parser.nextToken();
calOut.add(parser.getText());
}
if(fieldName == 'city'){
system.debug('city ---->'+parser.getText());
parser.nextToken();
calOut.add(parser.getText());
}
}
}
return calOut;
}
}
JSON File: