2016-10-09 2 views
0

also versuche ich eine Unicode-String U+1F600 von json in ein UILabel kommen, aber eine verdammt gute Zeit zu haben.Swift 3 konvertieren Unicode-String U + 1F600

Hat jemand das angetroffen? Es scheint auch, JSON kommt als \u1f600 hat die gleichen Probleme.

Ich habe diese Methode ohne Glück versucht: Emoji characters cannot be encoded to JSON

Vielen Dank

+0

'U + 1F600' und' \ u1f600' nicht gültig sind als JSON . Können Sie zeigen, welche Bytefolge Sie erhalten haben? – OOPer

+0

Dies könnte helfen: http://StackOverflow.com/a/32555223/1630618 – vacawama

Antwort

1

Dank vacawama und Edmar, beide hat mir geholfen, die Lösung zu finden, die sich wie folgt dar:

if let unicode = definition["unicode"] as? String { 
    if let int = Int(unicode.replacingOccurrences(of: "U+", with: ""), radix: 16) { 
     if let scalar = UnicodeScalar(int) { 
      let string = String(scalar) 
      emoji.text = string 
     } 
    } 
} 
0

In Ihrem JSON-Antwort, tut \u1f600 kommt in einem String-Format? Wenn ja, versuchen Sie dies:

let transform = "Any-Hex/Java" 
let input = "\\u1f600" as NSString 
var output = input.mutableCopy() as NSMutableString 

CFStringTransform(output, nil, transform as NSString, 1) 

println("output: \(output)")