title: NSJSONSerialization - How to convert JSON into NSArray properly?
body: <p>I encountered the following problem:
  I want so connect my iPhone-App with a database on a server. Therefore I use some (simple) .php files to manage the access to the DB. Inserting new data already works but I have some trouble to convert fetched data into a NSMutableArray :</p>
  
  <pre><code>NSURL *contentURL = [NSURL URLWithString:[kHOSTURL stringByAppendingString:kGETBarsURL]];
  NSLog(@"URL : %@", contentURL);
  
  NSData *contentData = [NSData dataWithContentsOfURL:contentURL];
  NSLog(@"Data : %@", contentData);
  
  NSError *e = nil;
  NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:contentData
                                                              options:kNilOptions
                                                                error:&amp;e];
  NSLog(@"JSON : %@", jsonArray);
  NSLog(@"Error : %@", e);
  </code></pre>
  
  <p>Output is like this (I 'XX' and shortened 'Data :') :</p>
  
  <pre><code>2012-04-28 13:49:37.229 XX[14434:f803] URL : http://xx/getBars.php
  2012-04-28 13:49:37.389 XX[14434:f803] Data : &lt;5b7b2275 6e697175 65223a22 34222c22 4e616d65 223a2254 65737422 2c224465 7461696c 73223a22 54686973 49734154 65737422 7d2c7b22 ...&gt;
  2012-04-28 13:49:37.390 XX[14434:f803] JSON : (null)
  2012-04-28 13:49:37.392 XX[14434:f803] Error : Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x6daa610 {NSDebugDescription=Garbage at end.}
  </code></pre>
  
  <p>If I open the page in a browser it looks like this:</p>
  
  <pre><code>[{"unique":"4","Name":"Test","Details":"ThisIsATest"},
   {"unique":"5","Name":"Test","Details":"ThisIsATest"},
   {"unique":"6","Name":"Test","Details":"ThisIsATest"},
   {"unique":"7","Name":"Test","Details":"ThisIsATest"},
   {"unique":"8","Name":"Test","Details":"ThisIsATest"},
   {"unique":"9","Name":"Test","Details":"ThisIsATest"},
   {"unique":"10","Name":"Test","Details":"ThisIsATest"}]
  </code></pre>
  
  <p>I've also tried other options in NSJSONSerialization but that did not work :( Can anybody help me here ?</p>
  
  <pre><code>2012-04-28 14:18:30.192 XX[14541:f803] Encoding : [{"unique":"4","Name":"Test","Details":"ThisIsATest"},{"unique":"5","Name":"Test","Details":"ThisIsATest"},{"unique":"6","Name":"Test","Details":"ThisIsATest"},{"unique":"7","Name":"Test","Details":"ThisIsATest"},{"unique":"8","Name":"Test","Details":"ThisIsATest"},{"unique":"9","Name":"Test","Details":"ThisIsATest"},{"unique":"10","Name":"Test","Details":"ThisIsATest"}]
  &lt;script type="text/javascript"&gt;
  
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-16106315-6']);
    _gaq.push(['_setDomainName', '.xx.de']);
    _gaq.push(['_trackPageview']);
  
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript';
  ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
  'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(ga, s);
    })();
  
  &lt;/script&gt;
  </code></pre>