gpt4 book ai didi

ios - 在swift 4中通过JSON url加载阿拉伯语言数据

转载 作者:行者123 更新时间:2023-11-30 11:19:41 25 4
gpt4 key购买 nike

`

    var Cities:[String] = [String]()
let requestURL = "https://----".addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)!

//Sending http post request
Alamofire.request(requestURL).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let swiftyJsonVar1 = JSON(responseData.result.value!)
let strjson = swiftyJsonVar1.rawString()!.data(using: String.Encoding.utf8)!
let swiftyJsonVar = JSON(strjson)
if let resData = swiftyJsonVar["Cities"].arrayObject {
print(swiftyJsonVar["Cities"].arrayObject! )
for a in resData {
let v = a as! [String:Any]
let City = v["Name"]!
Cities.append(City as! String)
}
self.TFrom.filterStrings(Cities) // put data from array to Component AutoComplete
self.TFrom.startVisible = true
self.TFrom.maxNumberOfResults = 5
self.TTo.filterStrings(Cities) // put data from array to Component AutoComplete
self.TTo.startVisible = true
self.TTo.maxNumberOfResults = 5

}
}
}

`当使用 JSON url 有英文数据时,这很好,但在阿拉伯语中返回空,有什么帮助吗? swift code to show data in url

最佳答案

您需要设置 Content-Type header 来请求:

var requestURL = URLRequest(url: URL(string: "https//:wwww.mywebsite.com")!)
requestURL.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")

关于ios - 在swift 4中通过JSON url加载阿拉伯语言数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51419780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com