title: Swift Mapping Data to [String: Any]
body: <p>I would like to convert a Data type to [String: Any], but the JSONSerialization tells me: </p>
  
  <blockquote>
    <p>Cannot force unwrap value of non-optional type 'Data'</p>
  </blockquote>
  
  <pre><code>var json: [String: Any]
              do{
                  let jsonEncoder = JSONEncoder()
                  let encodedJson = try jsonEncoder.encode(message)
                  json = try JSONSerialization.data(withJSONObject: encodedJson!, options: []) as? [String : Any]
              } catch {
                  log.error(error.localizedDescription)
              }
  return .requestParameters(parameters: json, encoding: JSONEncoding.default)
  </code></pre>
  
  <p>If I remove the '!' from encodedJson, then the Message occure:</p>
  
  <blockquote>
    <p>Value of optional type '[String : Any]?' not unwrapped; did you mean to use '!' or '?'?</p>
  </blockquote>
  
  <p>If I remove the '?' from any?, then I use json without initializing it, of course</p>
  
  <p>Didn't know how to fix this (new swift coder)</p>
  
  <p>Hope this is not a stupid question</p>