swift - 如何删除打印 URL 时不断出现的“&”?
问题描述
如何删除打印 URL 时不断出现的“&”?为什么还会出现?
var url = URLComponents()
url.scheme = "http"
url.host = "api.openweathermap.org"
url.queryItems = [
URLQueryItem(name: "/data", value: ""),
URLQueryItem(name: "/2.5", value: ""),
URLQueryItem(name: "/weather?", value: ""),
URLQueryItem(name: "lat", value: "35"),
URLQueryItem(name: "lon", value: "-139")
]
print(url.string!)
// http://api.openweathermap.org?/data=&/2.5=&/weather?=&lat=35&lon=-139
新问题:
如何将以下坐标转换为字符串?
(currentLocation.coordinate.latitude)
解决方案
/data/2.5/weather
是路径,而不是查询项。尝试:
var url = URLComponents()
url.scheme = "http"
url.host = "api.openweathermap.org"
url.path = "/data/2.5/weather"
url.queryItems = [
URLQueryItem(name: "lat", value: "35"),
URLQueryItem(name: "lon", value: "-139")
]
推荐阅读
- flutter - 尝试添加图标时出现此错误:类型“String”不是“函数结果”的“IconData”类型的子类型
- react-navigation - 顶级堆栈导航器看不到孙堆栈导航器的屏幕选项(react-navigation 5)
- xampp - Magento 重定向到 xampp 仪表板
- node.js - 评估函数后等待请求
- mlt - MLT 配置文件和 MLT 预设有什么区别?
- c# - c#:如何解析和验证具有自动生成格式的日期时间字符串
- azure-data-factory - 如何在大型 Azure 数据架构(多个 ADF、数据湖、Spark/Hadoop 集群)中管理架构元数据?
- reactjs - 单元测试失败无法找到元素
- css - 使用悬停 CSS 的按钮在按下按钮后截断文本
- c# - 替换文本中的所有匹配文本