2012-12-24 139 views
0
特殊字符

我現在NSJSONSerialization在解析JSON

NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"url"]]; 
NSError *jsonError = nil; 
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError]; 


NSDictionary *jsonDictionary = (NSDictionary *)jsonObject; 

[self setTableData:jsonDictionary]; 

解析但它不會解析因爲JSON特殊字符,如字母「U」我的JSON當我刪除'ü'來自JSON,它的工作正常。我試過上面的代碼和:

options:utf8... 

有誰知道我該如何解決這個問題?

+0

您的字符串編碼錯誤/轉換。如果編碼正確並且UTF8轉換爲Unicode,那麼JSON將沒有問題。 –

回答

0

嘗試使用NSString,您可以使用它顯式指定編碼。例如:

NSString *string = [NSString stringWithContentsOfURL:webURL encoding:NSUTF8StringEncoding error:&error]; 

然後,您可以轉換的NSString對象的NSData然後做JSON序列..

0

試圖改變NSJSONReadingMutableContainersNSJSONReadingMutableLeaves。這解決了我類似的問題。

+0

謝謝,我已經試過了,但它不工作。 – Frenck

+0

你可以驗證你的數據是UTF-8格式嗎?如果沒有,請在調用NSJSONSerialization之前先將其轉換爲 – Misha

+0

數據位於UTF8中 – Frenck