title: How to send JSON data using POST method swift
body: <p>How to send JSON data using POST method to server in SWIFT</p>
  
  <p>For Objective C i use this</p>
  
  <pre><code>NSMutableDictionary *get = [[NSMutableDictionary alloc]init];
  [get setObject:validEmailTF.text forKey:@"email"];
  NSData* jsonData = [NSJSONSerialization dataWithJSONObject:get options:kNilOptions error:nil];
  NSString *jsonInputString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  NSString *post = [[NSString alloc]initWithFormat:@"r=%@",jsonInputString];
  
  NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",forgetPasswordUrl]];
  
  NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
  NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120.0];
  [request setURL:url];
  [request setHTTPMethod:@"POST"];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPBody:postData];
  
  NSError *error;
  NSURLResponse *response;
  NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  if (responseData != nil)
  {
      jsonDict = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&amp;error];
      NSLog(@"Values =======%@",jsonDict);
  }
  </code></pre>
  
  <p>Convert this code in Swift language. 
  <a href="https://i.stack.imgur.com/fexWK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fexWK.png" alt="enter image description here"></a>
  Thanks</p>