2013-05-09 138 views
2

在我的代碼,我下載UTF8編碼的JSON數據,這是理想與NSJSONSerialization工作,但是當我得到的分析對象,它充滿了編碼問題,如:NSJSONSerialization JSONObjectWithData:選項:錯誤:編碼問題

"Jo\U00e3o e Maria - Ca\U00e7adores de Bruxas"

(它必須是「Joãoe Maria - Caçadoresde Bruxas」)。嘗試沒有成功重新編碼它的ASCII,Unicode和其他人:

NSData *downloadedData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:requestURL cachePolicy:cachePolicy timeoutInterval:timeoutInterval] returningResponse:NULL error:&error]; 
NSDictionary *serializedDictionary = [NSJSONSerialization JSONObjectWithData:downloadedData options:NSJSONReadingAllowFragments error:&error]; 

編輯:當我打印使用此,它正確地顯示:

NSLog(@"Test: %@", [[NSString alloc] initWithData:downloadedData encoding:NSUTF8StringEncoding]); 
+0

所以沒有問題了嗎? – geo 2013-05-09 15:41:41

+0

你如何檢查分析的數據?如果您使用的是NSLog,則可能會打印轉義字符,例如\ U00e3用於ã。 – Don 2013-05-09 15:55:47

+0

謝謝,我在NSLog中測試它,因爲我仍然沒有可用的UI,但它在UILabel中工作。 – 2013-05-09 16:04:42

回答

0

這些都是UTF8編碼的字符。格式是正確的,將它們放在UILabel或其他東西上,它們將按照您的預期顯示。

0

如果需要拋光文本本身嘗試

NSString * s = [NSString stringWithUTF8String:[<your_string> UTF8String]];