我是json的nsdata 当我输入字符串时我得到#1495;#1493;#1507; #1492;#1510;#1493;#1511; +&安培;在每个标签之前 我需要希伯来语 代码是
let json_url = NSURL(string: "http://itaypincas7.ipage.com/WigiTech-DB/createJSON.php")
let jsonData = NSData(contentsOfURL: json_url!)
do {
let json = try NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
for (_, subJson) in json {
let id = Int(subJson["id"] as! String)
let name: String = subJson["name"] as! String
let area: String = subJson["area"] as! String
let latitude = CLLocationDegrees(CGFloat(Float(subJson["latitude"] as! String)!))
let longitude = CLLocationDegrees(CGFloat(Float(subJson["longitude"] as! String)!))
let beachNew = BeachNew(id: id!, name: name, area: area, latitude: latitude, longitude: longitude)
beachesList.append(beachNew)
}
答案 0 :(得分:1)
您可以使用NSAttributedString
替换HTML实体。这是解码name
变量的示例。
let name: String = subJson["name"] as! String
let nameData = name.dataUsingEncoding(NSUTF8StringEncoding)!
let options: [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]
let attributedName = try NSAttributedString(data: nameData, options: options, documentAttributes: nil)
let decodedName = attributedName.string
decodedName
的值会将所有实体替换为您正在寻找的希伯来字符。