0
我得到一些DATAS使用JSON,但是當我得到的數據name
小號特林是這樣的:問題與數據字符串轉換爲UTF8
{
code = 200;
found = 1;
name = "\\u0635\\u0641\\u062d\\u0647 \\u0631\\u0633\\u0645\\u06cc \\u0633\\u0627\\u06cc\\u062a \\u0648\\u0631\\u0632\\u0634 \\u06f3";
}
如何解決這個問題?我試圖將其轉換爲UTF8編碼,但仍然沒有!我不得不說的網址在Safari中正常工作與UTF8編碼
這裏是我的代碼:
let userURL: String = "https://myurl.com/xxx"
let ut8 = userURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string:ut8!)!, completionHandler: { (data, response, error) -> Void in
// Check if data was received successfully
if error == nil && data != nil {
do {
if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary {
print(jsonResult)
}
.....
}
問題就迎刃而解了:有在服務器出了問題,現在固定
這不是JSON字符串,它的字典表示。你確定JSON包含這些Unicode令牌嗎? – vadian
@vadian我只是編輯我的Q標題 –
不要將'name'字符串轉換並分配給UILabel的'text'屬性。怎麼了? – vadian