当我尝试在浏览器上获取商店的坐标时,我使用此链接获得了json结果,没有错误:
"https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name=ستاربكس&key=#####"
但是当我在Xcode中通过Alamofire进行HTTP请求时
let url = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&name=ستاربكس&key=####"
let requestURL =
Alamofire.request(url).responseJSON
{ response in
print(response.result.debugDescription)
print(response.request) // original URL request
print(response.response)
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
我的所有版画都没有了!!它为什么这样做?但是,当我通过Alamofire请求搜索英文名称时,它可以工作!
答案 0 :(得分:0)
我的猜测是苹果公司的框架中出现了拉丁和阿拉伯字符混合的问题。您可以通过分离两个组件来解决它:
var urlComponents = URLComponents(string: "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=24.712587,46.673184&radius=5000&key=xxx")!
urlComponents.queryItems?.append(URLQueryItem(name: "name", value: "ستاربكس"))
let requestURL =
Alamofire.request(urlComponents).responseJSON { response in
...
}