title: How to solve Null response on receive data from server with JSON Swift and PHP
body: <p>I'm trying to send and receive data from an app and server using Swift, JSON and PHP but I receive all null values. 
  the response of server is:</p>
  
  <pre><code> porte
   &lt;null&gt;
   venditore
   &lt;null&gt;
   cilindrata
   &lt;null&gt;
   ordine
   &lt;null&gt;
   catalizzatore
   &lt;null&gt;
   IVA
   &lt;null&gt;
   percentualeammortamento
   &lt;null&gt;
   cognome
   &lt;null&gt;
   garanzia
   &lt;null&gt;
   targa
   &lt;null&gt;
   alimentazione
   &lt;null&gt;
   marca
   &lt;null&gt;
   KM
   &lt;null&gt;
   sinistri
   &lt;null&gt;
   modello
   &lt;null&gt;
   telaio
   &lt;null&gt;
   indirizzo
   &lt;null&gt;
   data
   &lt;null&gt;
   colore
   &lt;null&gt;
   dossier
   &lt;null&gt;
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>import UIKit
  class SaveViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
  
  
  
  var data_save:String! ="SomeString"
  var venditore_save:String! ="SomeString"
  var ordine_save:String! ="SomeString"
  var dossier_save:String! ="SomeString"
  var marca_save:String! ="SomeString"
  var modello_save:String! ="SomeString"
  var cilindrata_save:String! ="SomeString"
  var targa_save:String! ="SomeString"
  var telaio_save:String! ="SomeString"
  var alimentazione_save:String! ="SomeString"
  var catalizzatore_save:String! ="SomeString"
  var porte_save:String! ="SomeString"
  var colore_save:String! ="SomeString"
  var km_save:String! ="SomeString"
  var garanzia_save:String! ="SomeString"
  var incidenti_save:String! ="SomeString"
  var cognome_save:String! ="SomeString"
  var indirizzo_save:String! ="SomeString"
  var iva_save:Bool! ="SomeString"
   var percentualeammortamento_save:String! ="SomeString"
  
   @IBAction func btnSignUp_Clicked(sender: UIButton) {
  let parameters = ["data":data_save, "venditore":venditore_save, "dossier":dossier_save,"ordine":ordine_save, "cognome":cognome_save,"indirizzo":indirizzo_save, "marca":marca_save, "modello":modello_save, "targa":targa_save, "telaio":telaio_save, "cilindrata":cilindrata_save, "alimentazione":alimentazione_save, "catalizzatore":catalizzatore_save, "KM":km_save, "porte":porte_save, "colore":colore_save, "sinistri":incidenti_save, "garanzia":garanzia_save, "IVA": String(iva_save), "percentualeammortamento":percentualeammortamento_save] as Dictionary&lt;String, String&gt;
  
  
      let url = NSURL(string: "myurl") //change the url
  
  
  
      let session = NSURLSession.sharedSession()
  
  
  
      let request = NSMutableURLRequest(URL: url!)
      request.HTTPMethod = "POST" //set http method as POST
  
      let err: NSError?
  
  
      request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(parameters, options:[])
  
  
      request.addValue("application/json", forHTTPHeaderField: "Content-Type")
      request.addValue("application/json", forHTTPHeaderField: "Accept")
  
  
  
  
  
      let task = session.dataTaskWithRequest(request) { data, response, error in
          guard data != nil else {
              print("no data found: \(error)")
              return
          }
  
  
  
          do {
              if let json = try NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? NSDictionary {
                  let success = json["success"] as? Int                                  
  
                  print("Success: \(success)")
              } else {
                  let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)    // No error thrown, but not NSDictionary
                  print("Error could not parse JSON: \(jsonStr)")
              }
          } catch let parseError {
              print(parseError)                                                          
  
              let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
              print("Error could not parse JSON: '\(jsonStr)'")
          }
      }
  
      task.resume()
  }
  
  
  
  
  
    @IBAction  func btnLoadUser_Clicked(sender: UIButton) {
  
  let url = NSURL(string: "myurl")
  
  let request = NSMutableURLRequest(URL: url!)
  
  
  
  let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
      data, response, error in
  
      if data == nil {
          print("request failed \(error)")
          return
      }
  
  
  
          do{
  
              let json = try! NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSDictionary
  
                  for (key, value) in json {
  
  
                      let data = try! NSJSONSerialization.dataWithJSONObject([key, value], options:[])
  
  
  
                      print(key)
  
                      print(value)}
  }catch {
              print("bom bom bom error")
          }
  
      }
      task.resume() } }
  </code></pre>
  
  <p>Here's the php code:</p>
  
  <pre><code>   &lt;?php 
  $ricambio = array();
  $ricambio['data'] = $_POST['data'];
  $ricambio['venditore'] = $_POST['venditore'];
  $ricambio['dossier'] = $_POST['dossier'];
  $ricambio['ordine'] = $_POST['ordine'];
  $ricambio['cognome'] = $_POST['cognome'];
  $ricambio['indirizzo'] = $_POST['indirizzo'];
  $ricambio['marca'] = $_POST['marca'];
  $ricambio['modello'] = $_POST['modello'];
  $ricambio['targa'] = $_POST['targa'];
  $ricambio['telaio'] = $_POST['telaio'];
  $ricambio['cilindrata'] = $_POST['cilindrata'];
  $ricambio['alimentazione'] = $_POST['alimentazione'];
  $ricambio['catalizzatore'] = $_POST['catalizzatore'];
  $ricambio['KM'] = $_POST['KM'];
  $ricambio['porte'] = $_POST['porte'];
  $ricambio['colore'] = $_POST['colore'];
  $ricambio['sinistri'] = $_POST['sinistri'];
  $ricambio['garanzia'] = $_POST['garanzia'];
  $ricambio['IVA'] = $_POST['IVA'];
  $ricambio['percentualeammortamento'] = $_POST['percentualeammortamento'];
  
  echo json_encode($ricambio);
  
  
  ?&gt;
  </code></pre>
  
  <p>Any solutions? Maybe the problem is the options:[] in </p>
  
  <pre><code> try NSJSONSerialization.JSONObjectWithData(parameters, options:[]
  </code></pre>