let JsonObject: [String: AnyObject] = [ "ean_code": [ "type": "match","value": "16743799" ] ]
然后我执行了请求
像这样
Alamofire.request(.GET,Constant.WebClIEnt.WS_URL + "/product?filters="+String(JsonObject),parameters:parameters)
但这给了我一个错误,这是一个canot绑定无效字符的URL
所以我编码了这个URL
let request = String(JsonObject).stringByAddingPercentEnCodingWithAllowedCharacters(NSCharacterSet.URLPasswordAllowedCharacterSet())!
这将编码URL但我再次这将给我以下错误
Request Failed with error: Error Domain=NSCocoaErrorDomain Code=3840 “InvalID value around character 0.”
UserInfo={NSDeBUGDescription=InvalID value around character 0.}
所以我的问题是如何将Json对象绑定到GET URL?
解决方法 做这样的事情let parameters: [String: AnyObject] = [ "filters": "merchantname","ean_code": [ "type": "match","value": "16743799" ]]do { let data = try NSJsONSerialization.dataWithJsONObject(parameters,options: .PrettyPrinted) let JsonString = Nsstring(data: data,enCoding: NSUTF8StringEnCoding) let urlEncodedJson = JsonString!.stringByAddingPercentEnCodingWithAllowedCharacters(.URLHostAllowedCharacterSet()) let urlString = "http://www.filter.com/¶ms=\(urlEncodedJson!)" let url = NSURL(string: urlString) // Trigger alaomofire request with url}catch let JsONError as NSError { print("\(JsONError)")}总结
以上是内存溢出为你收集整理的ios – 在Alamofire中的swift中在GET请求中发送json对象全部内容,希望文章能够帮你解决ios – 在Alamofire中的swift中在GET请求中发送json对象所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)