title: Converting JSON to NSData, and NSData to JSON in Swift
body: <p>I'm having problems converting a <code>JSON</code> element into <code>NSData</code>, and an <code>NSData</code> variable back into <code>JSON</code> in Swift.</p>
  
  <p>Firstly, I'd like to extract the <code>encryptedData</code> element of the following JSON data:</p>
  
  <pre><code>{
      "transactionID" : 12345,
      "encryptedData" : [-67,51,-38,61,-72,102,48]
  }
  </code></pre>
  
  <p>into an NSData <code>encryptedData</code> variable but can't seem to be able to do it. I'm using <code>SwiftyJSON</code> to parse the <code>JSON</code> as follows:</p>
  
  <pre><code>let list: Array&lt;JSON&gt; = json["encryptedData"].arrayValue!
  </code></pre>
  
  <p>But this gives me an array of ScalarNumber which I don't know how to store into an <code>NSData</code> object.</p>
  
  <p>Secondly, I'd like to generate <code>JSON</code> back from the same <code>NSData</code> object: </p>
  
  <pre><code>let jsonObject = [
      "transactionID" : 12345,
      "encryptedData" : encryptedData
  ]
  </code></pre>
  
  <p>But the NSData <code>encryptedData</code> object doesn't get converted into [-67,51,-38,61,-72,102,48], it just seems to nullify the JSON string. </p>
  
  <p>Any ideas?</p>