-1

I am using data from JSON but can’t get rid of tag html, ex. <p> </p> &#.#8217 I have followed all suggestion which have been posted in the forum here but it’s still not working. Please kindly help and suggest. Here are my codes

    @IBOutlet weak var nameUILabel: UILabel! 

    var dogs:JSON? {

    didSet {

        self.functionFood()
    }
}

   func functionFood() {

    self.nameUILabel.text = self.dogs?["title"].string


    }

   }
Community
  • 1
  • 1
user2952122
  • 75
  • 1
  • 6

1 Answers1

0
extension String {
    var html2String:String {
        return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil, error: nil)!.string
    }
}


"<p>&#8217Paragraph1 Test&#8217</p><p>&#8217Paragraph2 Test&#8217</p>".html2String   // "’Paragraph1 Test’\n’Paragraph2 Test’\n"
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571