title: Encoding issue: Cocoa Error 261?
body: <p>So I'm fetching a JSON string from a php script in my iPhone app using:</p>
  
  <pre><code>NSURL *baseURL = [NSURL URLWithString:@"test.php"];
  NSError *encodeError = [[NSError alloc] init];
  NSString *jsonString = [NSString stringWithContentsOfURL:baseURL encoding:NSUTF8StringEncoding error:&amp;encodeError];
  NSLog(@"Error: %@", [encodeError localizedDescription]);
  NSLog(@"STRING: %@", jsonString);
  </code></pre>
  
  <p>The JSON string validates when I test the output. Now I'm having an encoding issue. When I fetch a single echo'd line such as:</p>
  
  <pre><code>{ "testKey":"é" }
  </code></pre>
  
  <p>The JSON parser works fine and I am able to create a valid JSON object. However, when I fetch my 2MB JSON string, I get presented with:</p>
  
  <pre><code>Error: Operation could not be completed. (Cocoa error 261.)
  </code></pre>
  
  <p>and a Null string. My PHP file is UTF8 itself and I am not using utf8_encode() because that seems to double encode the data since I'm already pulling the data as NSUTF8StringEncoding. Either way, in my single-echo test, it's the approach that allowed me to successfully log \ASDAS style UTF8 escapes when building the JSON object.</p>
  
  <p>What could be causing the error in the case of the larger string?</p>
  
  <p>Also, I'm not sure if it makes a difference, but I'm using the php function addslashes() on my parsed php data to account for quotes and such when building the JSON string.</p>