Encoding issue: Cocoa Error 261?

后端 未结 5 690
耶瑟儿~
耶瑟儿~ 2021-02-12 14:01

So I\'m fetching a JSON string from a php script in my iPhone app using:

NSURL *baseURL = [NSURL URLWithString:@\"test.php\"];
NSError *encodeError = [[NSError a         


        
5条回答
  •  野的像风
    2021-02-12 14:36

    I'm surprised no one has mentioned using a different encoding value instead of NSUTF8StringEncoding when calling [NSString stringWithContentsOfFile:encoding:error:].

    I also got Cocoa error 261 when parsing a JSON file. I just went through the list of NSString encodings until one worked. Fortunately the first one worked for me: NSASCIIStringEncoding!

    You can also use NSString stringWithContentsOfFile:usedEncoding:error: to try to find the correct encoding (as described here: How to use stringWithContentsOfURL:encoding:error:?).

提交回复
热议问题