折腾:
【已解决】iOS中UIWebView中如何改变URL并刷新页面
期间,想要实现,url中的query string编码
变成:
http://xx.xx.xx.xx/skrDev/src/report/dealer.html?t=1510899512424&cid=2
想起来了,貌似Alamofire中有这个功能?
swift url query string encode
ios – Swift – encode URL – Stack Overflow
ios – How to encode a URL in Swift – Stack Overflow
ios – Swift: string url encoding not working as expected – Stack Overflow
ios – encoding url using swift code – Stack Overflow
swift url json to query string
ios – How to send Json as parameter in url using swift – Stack Overflow
ios – Best way to parse URL string to get values for keys? – Stack Overflow
ios – Sending json object in GET request in swift in Alamofire – Stack Overflow
Convert dictionary to query string in swift? – Stack Overflow
Building URLs with NSURLComponents and NSURLQueryItems – Grok Swift
然后又遇到:
【总结】
此处可以用:
//convert query dict to query string
// {
// “t” : 1510906527744,
// “tabId” : “”
// }
// -> “?t=1510906527744&tabId=”
//
func queryDictToStr(queryParaDict: [String: Any]) -> String {
var urlComponents = URLComponents()
urlComponents.queryItems = queryParaDict.map { (arg) -> URLQueryItem in
let (key, value) = arg
let valueStr = “\(value)”
return URLQueryItem(name: key, value: valueStr)
}
var queryParaStr = “”
if let componentsAbsUrl = urlComponents.url?.absoluteString {
queryParaStr = componentsAbsUrl //”?t=1510906527744&tabId=”
}
let encodedQueryParaStr = queryParaStr.encodedUrl
return encodedQueryParaStr
}
将dict的query parameters:
{
“t” : 1510906527744,
“tabId” : “”
}
转换为问号开头的查询字符串了:
?t=1510906527744&tabId=
后续优化: