title: How to send JSON data over NSURLConnection
body: <p>I have successfully created a method which connects to my web service and POSTS a string and receives a string response. However, I am now trying to POST a JSON dictionary created using NSJSONSerialization. However, Xcode is giving me an error. I have tried to convert my initial code. Relevant lines below...</p>
  
  <pre><code>NSData* loginDataJSON = [NSJSONSerialization dataWithJSONObject:loginDataDictionary options:NSJSONWritingPrettyPrinted error:&amp;error];
  [request setValue:loginDataJSON forHTTPHeaderField:@"loginDataJSON"];
  [request setHTTPBody:[loginDataJSON dataUsingEncoding:NSUTF8StringEncoding]];
  </code></pre>
  
  <p>The second line heres complains that I am using NSData where an NSString is required.
  The third line complains that <code>loginDataJSON</code> may not respond to <code>dataUsingEnconding</code></p>
  
  <p>I seem to be forcing an NSData object (because that what NSJSONSerialization gives me) where it cannot be used. Am I best trying to convert the JSON into a string to use with my existing request code, or should/can I change my request code to accept NSData as opposed to an NSString?</p>