您尚未提供足夠的信息來提供除含糊答案之外的任何內容,但您的確有一些選擇。
最重要的是,您有一個「error
」參數,您應該打印出結果。你也可以在NSString類中使用稍微好一點的API。
更改您的代碼是這樣的:
NSError *error = NULL;
NSStringEncoding actualEncoding;
// variable names in Objective-C should usually start with lower case letters, so change
// URL in your code to "url", or even something more descriptive, like "urlOfOurString"
NSString *string = [[NSString alloc] initWithContentsOfURL:urlOfOurString usedEncoding:&actualEncoding error:&error];
if(string)
{
NSLog(@"hey, I actually got a result of %@", string);
if(actualEncoding != NSUTF8StringEncoding)
{
// I also suspect the string you're trying to load really isn't UTF8
NSLog(@"and look at that, the actual encoding wasn't NSUTF8StringEncoding");
}
} else {
NSLog(@"error when trying to fetch from URL %@ - %@", [urlOfOurString absoluteString], [error localizedDescription]);
}
對不起,如果我不夠清楚,但是,它實際上是UTF8,總是。我會試着看看這是否能讓這個過程更加穩定。雖然我真的想知道它是否會成爲服務器端的問題? – Mathias 2013-03-08 18:19:31