ios - While setting NSString to NSURL, NSURL is returning nil value -


i have parse return of json api i've taken url string , after passed nsurl in nslog showing nil. here code,

nsstring *urlstring=[nsstring stringwithformat:@"http://api.v3.factual.com/t/places?q=%@&geo={\"$circle\":{\"$center\":[19.9909631,73.8034808],\"$meters\":40000}}&limit=20&key=123456",[self.strurl lowercasestring]]; nsurl *url=[[nsurl alloc]initwithstring:urlstring ]; nsurlrequest *req = [nsurlrequest requestwithurl:url]; 

thanks in advance.

you must encode url contains special characters, try this

nsstring *paramstring=[nsstring stringwithformat:@"/t/places?q=%@&geo={\"$circle\":{\"$center\":[19.9909631,73.8034808],\"$meters\":40000}}&limit=20&key=123456",[self.strurl lowercasestring]];  nsstring *encodedsearchstring = [paramstring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];  nsstring *urlstring = [nsstring stringwithformat:@"http://api.v3.factual.com%@", encodedsearchstring]; nsurl *url = [nsurl urlwithstring:urlstring]; nslog(@"urlstring %@",url) 

hope helps


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -