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
Post a Comment