title: Swift: check if jsonObjectWithData is json or not
body: <p>I have a swift application that communicates by http with a server,</p>
  
  <p>The answers I get by this server may be json, or not. I need to check what they are to print the answer as a <code>Dictionary</code> or as an <code>Array</code>, in order to avoid the <code>fatal error: unexpectedly found nil while unwrapping an Optional value</code> at the <code>NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary</code></p>
  
  <p>This is my <code>jsonObjectWithData</code>:</p>
  
  <pre><code>var dataVal: NSData =  NSURLConnection.sendSynchronousRequest(request, returningResponse: &amp;response, error:nil)!
  elimResponse = response?.description        
  elim = NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
  </code></pre>
  
  <p>What I try to get is something like:</p>
  
  <pre><code>if dataVal is Json{
      elim = NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
      println(elimJson)
      }else{
      elim = NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSArray
      println(elim)
      }
  </code></pre>
  
  <p>Thank you for your help. Regards.</p>