ios - Alamofire Get Request and JSON Response -
i'm trying use yoda api , send request using alamofire swift framework. know api correctly working, have tested endpoint mashape api key multiple times. can see requests being sent (homepage of mashape under application). json response nil
.
func handlerequest(words:string){ var saying = words.stringbyreplacingoccurrencesofstring(" ", withstring: "+"); saying = "?sentence=" + saying; let url = nsurl(string: (baseurl+saying)); println(url); var response:string; alamofire.manager.sharedinstance.session.configuration.httpadditionalheaders = additionalheaders; alamofire.request(.get, url!).responsejson { (_, _, json, _) in println(json); } }
the words string can "this first sentence" , automatically replace spaces "+" per api spec. please ignore multiple println
statements, debugging.
this proof of concept code, purposely not doing error checking , isn't pretty reason. if have suggestions appreciate them.
for reason it's issue i've alamofire request json. way handle json requests using alamofire :
alamofire.request(.get, urlto, parameters: nil, encoding: .url).responsestring(completionhandler: { (request: nsurlrequest, response: nshttpurlresponse?, responsebody: string?, error: nserror?) -> void in // convert response nsdata handle swiftyjson if let data = (responsebody nsstring).datausingencoding(nsutf8stringencoding) { let json = json(data: data) println(json) } })
i recommend using swiftyjson manage json in better , easy way, it's you.
i hope you.
Comments
Post a Comment