Encoding issue: Cocoa Error 261? Encoding issue: Cocoa Error 261? json json

Encoding issue: Cocoa Error 261?


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:?).


Don't know if this is your problem, but I just had a similar thing (stringWithContentsOfFile, no JSON), and the problem was that the file had CRLF (windows) line-endings and Western-whatever-it's-called encoding. I used SubEthaEdit to convert to LF (Mac/Unix line-endings) and UTF-8 encoding, and now everything works fine.


Encoding issue: Cocoa Error 261? I solved this issue by trying different encoding. First I was using NSUTF8 then I switched to NSASCIIStringEncoding and it worked.

NSString* path = [[NSBundle mainBundle] pathForResource: @"fileName" ofType: @"type"];NSData* data = [NSData dataWithContentsOfFile:path];NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];NSLog(@"%@",string);