0

i was a nsdata from json when i put in string i get "#1495;#1493;#1507; #1492;#1510;#1493;#1511; +& Before each tag i need it in Hebrew the code is

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)
        }
1
  • 4
    Questions on Stack Overflow must be in English. Commented Sep 26, 2015 at 13:09

1 Answer 1

1

You can use NSAttributedString to replace the HTML entities. Here's an example for decoding the name variable.

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

The value of decodedName will have all entities replaced with the Hebrew characters you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.