title: Alamofire: FAILURE responseSerializationFailed
body: <p>I'm trying to get the <code>JSON</code> from a URL to download using <code>Alamofire</code>.</p>
  
  <pre><code>Alamofire.request(requrl, method: .get, encoding: JSONEncoding.default)
          .responseJSON { response in
              print(response.result)
              print(response.value)
              debugPrint(response)
  
  
              }
  </code></pre>
  
  <p>However the value of <code>response.value</code> is nil, and the request result status is FAILURE. The following is in the logs:</p>
  
  <pre><code>&gt;[Data]: 919 bytes
  [Result]: FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
  [Timeline]: Timeline: { "Request Start Time": 561988246.258, "Initial Response Time": 561988246.446, "Request Completed Time": 561988246.447, "Serialization Completed Time": 561988246.447, "Latency": 0.189 secs, "Request Duration": 0.189 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.190 secs
  </code></pre>
  
  <p>The JSON url in a browser returns:
  <a href="https://i.stack.imgur.com/X2J2B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2J2B.png" alt="enter image description here"></a></p>
  
  <p>php script</p>
  
  <pre><code>&lt;?php
  header('Content-type: application/json');
  //header('Content-Type: html; charset=utf-8');
  $sqlstatement = $_GET["sqlstatement"];
  // Create connection
  $dbConnection=mysqli_connect("***.***.gear.host","****","*****!","****");
  
  //$sqlstatement = "SELECT * FROM reeds.tbl_user";
  // Check connection
  if (mysqli_connect_errno())
  {
    // Print error message 
    echo mysqli_connect_error();
  }
  
  // Stores SQL statement, selecting all objects from testcomputing.name
  
  
  // Check to ensure results &gt; = 1
  if ($result = mysqli_query($dbConnection, $sqlstatement))
  {
      // If so, then create a results array and a temporary one to hold the data
      $resultArray = array();
      $tempArray = array();
  
      // Loop through each row in the result set
      while($row = $result-&gt;fetch_object())
      {
          // Add each row into our results array
      $tempArray = $row;
       array_push($resultArray, $tempArray);
      }
  
      // Encode the array to JSON and output the results
      echo json_encode($resultArray);
  }
  
  // Close connections
  mysqli_close($dbConnection);
  ?&gt;
  </code></pre>