title: JSON parse error in iOS
body: <p>I am trying to parse json response(which I get from result tag of a SOAP webservice response) as shown in pictures with following lines.</p>
  
  <pre><code>NSString *soapMessage = [NSString stringWithFormat:@"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"
                           "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;"
                           "&lt;soap:Body&gt;"
                           "&lt;GetPhotoSession xmlns=\"http://tempuri.org/\"&gt;"
                           "&lt;UserID&gt;%@&lt;/UserID&gt;"
                           "&lt;photoSessionID&gt;%@&lt;/photoSessionID&gt;"
                           "&lt;/GetPhotoSession&gt;"
                           "&lt;/soap:Body&gt;"
                           "&lt;/soap:Envelope&gt;",[HelperClass retrieveStringForKey:kUserID],self.currentSession.sessionID];
  
  NSURL *url = [NSURL URLWithString:kBaseURL];
  NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
  NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
  
  [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  [theRequest addValue: @"http://tempuri.org/GetPhotoSession" forHTTPHeaderField:@"SOAPAction"];
  [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  [theRequest setHTTPMethod:@"POST"];
  [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
  NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  
  if( theConnection ) {
      self.webResponseData = [NSMutableData data];
  }else {
      NSLog(@"Some error occurred in Connection");
  
  }
  
  -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
      [self.webResponseData  setLength:0];
  }
  
  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
      [self.webResponseData  appendData:data];
  }
  
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
      NSLog(@"Some error in your Connection. Please try again.");
  }
  
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection {
      NSLog(@"Received Bytes from server: %d", [self.webResponseData length]);
      NSString *myXMLResponse = [[NSString alloc] initWithBytes: [self.webResponseData bytes] length:[self.webResponseData length] encoding:NSUTF8StringEncoding];
      NSLog(@"%@",myXMLResponse);
  
      NSError *errorPointer;
  
      NSDictionary *dict = [XMLReader dictionaryForXMLString:myXMLResponse error:&amp;errorPointer];
  
      NSString *jsonData = dict[@"soap:Envelope"][@"soap:Body"][@"GetPhotoSessionResponse"][@"GetPhotoSessionResult"][@"text"];
  
      NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
      id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&amp;errorPointer];
  
      NSLog(@"%@",[json objectForKey:@"Head"]);
  }
  </code></pre>
  
  <p>But I am getting nil in "json" object. Here is the pastie link for JSON response <a href="http://pastie.org/9799331" rel="nofollow">http://pastie.org/9799331</a>. Following is the description of error pointer.</p>
  
  <p>Printing description of errorPointer:
  Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7d0156a0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}</p>