我正在向URL發出請求。帶有重音/拉丁字符的JSON請求
其中一個團隊有拉丁字符Ñ似乎使我的JSON零,因此沒有數據顯示在我導出數據的表中。我做了一些研究,我相信我需要將它編碼爲NSISOLatin1StringEncoding。
我正在使用SwiftyJSON來解析JSON。
let cuartoURL = NSURL(string: cuartoURLString)
//initializes request
let request = NSURLRequest(URL: cuartoURL!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.currentQueue()) { response, jsonDataRequest4, error in
if jsonDataRequest4 != nil {
let dataRequest4 = jsonDataRequest4
//println(NSString(data:dataRequest4, encoding: NSUTF8StringEncoding))
//takes data, saves it as json
let cuartoJSON = JSON(data: jsonDataRequest4)
//checks to see that contents != nil, meaning the JSON file was found
if cuartoJSON != nil {
equiposList.removeAll(keepCapacity: false)
//counts number of teams
numeroDeEquipos = cuartoJSON["lista-equipos"].count
println(numeroDeEquipos)
//saves each variable and appends to a array
for var index = 0; index < numeroDeEquipos;++index {
var equipoID = Int(cuartoJSON["lista-equipos"][index]["EquipoID"].number!)
var nomEquipo = cuartoJSON["lista-equipos"][index]["nomEquipo"].string
var nomGrupo = cuartoJSON["lista-equipos"][index]["nomGrupo"].string
var equiposNuevo = listaEquipos(equipoID: equipoID, nomEquipo: nomEquipo!, nomGrupo: nomGrupo!)
equiposList.append(equiposNuevo)
self.tableView.reloadData()
}
//loadingActivity.hideLoadingActivity(success: true, animated: false)
//reloads data once json is complete
self.tableView.reloadData()
} else {
//loadingActivity.hideLoadingActivity(success: false, animated: true)
println("NIL JSON")
}
}
由於名字的性質/的,我們正在處理我們的人等使用ISO-8859-1編碼。我正在使用swiftyJSON來解析JSON,有什麼辦法可以讓我簡單地改變swiftyJSON使用的編碼嗎? 這裏是源文件:https://raw.githubusercontent.com/SwiftyJSON/SwiftyJSON/master/Source/SwiftyJSON.swift – FredLoh
不需要,UTF-8支持拉丁-1可以表示的所有字符等等。 – Krumelur