This is my apex code
public PageReference find() {
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
String url = 'http://clozer.3spire.net/public/user/'+strTag+'/'+cities;
req.setEndpoint(url);
req.setMethod('GET');
//these parts of the POST you may want to customize
req.setCompressed(false);
req.setBody('key1=value1&key2=value2');
req.setHeader('Content-Type', 'application/json');
try {
res = http.send(req);
} catch(System.CalloutException e) {
system.debug('Callout error: '+ e);
//result = ''+e;
}
data = (Map<String, Result>)JSON.deserialize(res.getBody(),Map<String, Result>.class);
lstResultWrapper = new List<ResultWrapper>();
for(Result obj: data.values())
{
lstResultWrapper.add(new ResultWrapper(obj));
}
return null;
}
public class Result
{
public String description {get;set;}
public String person_name {get;set;}
public String email {get;set;}
public String exparience {get;set;}
public String location {get;set;}
}
public class ResultWrapper{
public Result objResult {get;set;}
public Boolean isSelected {get;set;}
public ResultWrapper(Result objResult){
this.objResult = objResult;
isSelected = false;
}
}
Json string is
{"0":{"description ":"","person_name":"Justin Townsley","email":"jlt@staranchor.com","exparience":null,"location":"Unknown"},"1":{"description ":"","person_name":"Dan Anderson","email":"danandersonmobile@yahoo.com","exparience":null,"location":"Unknown"},"2":{"description ":"","person_name":"Artak Robert Melkonyan","email":"artakrobert@gmail.com","exparience":null,"location":"Unknown"},"3":{"description ":"","person_name":"Sanjay Anandaram","email":"sanjayanandaram@gmail.com","exparience":null,"location":"Unknown"},"4":{"description ":"","person_name":"Katia Gaika","email":"katia.gaika@gmail.com","exparience":null,"location":"Unknown"},"5":{"description ":"","person_name":"Sidnei Gon\u008dalves","email":"sidnei.goncalves@up2place.com.br","exparience":null,"location":"Unknown"},"6":{"description ":"","person_name":"Michel Koch","email":"michelkoch@hotmail.com","exparience":null,"location":"Unknown"},"7":{"description ":"","person_name":"Shannon Lydell Carter, MBA Technolo","email":"Shannon@truegame.com","exparience":null,"location":"Unknown"},"8":{"description ":"","person_name":"Jacob Hagemann","email":"jhagemann@gmail.com","exparience":null,"location":"Unknown"},"9":{"description ":"","person_name":"Amaresh Ramaswamy","email":"amareshr@live.com","exparience":null,"location":"Unknown"}}
Why this error is happening and how to get ride of this.Thanks in Advance
Best Answer
So After discussion with moin. We found issue.
After debugging the issue. I found the reason, issue in end point url
for example
strTag = Business activities
then we need to replace space between Business and activities with%20
.After replacing this it worked like charm..
Issue related to end point..
AFter changing this to
it worked...
I Know if we used
Business activities
without %20 then it wil automatically changed the space to %20 but it didn't worked...Noted:- We tried using
EncodingUtil.urlEncode(strTag, 'UTF-8')
but in url encoding space replace with + so that the reason it didn't worked.