title: Decoding JSON strings containing arrays
body: <p>I'm encoding and decoding to and from JSON strings using JSONSerialization in the class below. I can encode both NSDictionaries &amp; NSArrays and I can decode strings that have been encoded using NSDictionaries but not strings that were encoded from arrays, it barfs at JSONSerialization.jsonObject( ...
  I can work without arrays, at a pinch but it would be nice to know why this is happening. Thoughts appreciated</p>
  
  <pre><code>let a = [1,2,3,4,5]  
  let s = JSON.Encode( a )!
  JSON.Decode( s ) // fails    
  
  let a = ["a" : 1, "b" : 2, "c" : 3 ]  
  let s = JSON.Encode( a )!
  JSON.Decode( s ) // works
  </code></pre>
  
  <p>-</p>
  
  <pre><code>class JSON: NSObject {
  
     static func Encode( _ obj: Any ) -&gt; String? {
  
         do {
             let data = try JSONSerialization.data(withJSONObject: obj, options:JSONSerialization.WritingOptions(rawValue: 0) )
  
             if let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) {
                 return string as String
             }
             return nil
         } catch let error as NSError {
             return nil
         }
     }
  
     static func Decode( _ s: String ) -&gt; (NSDictionary?) {
  
         let data = s.data(using: String.Encoding.utf8, allowLossyConversion: false)!
         do {
             // fails here to work on anything other than "{ a : b, c : d }"
             // hates any [1,2,3] arrays in the string
             let json = try JSONSerialization.jsonObject(with: data, options:JSONSerialization.ReadingOptions.mutableContainers) as! NSDictionary
             return json
         } catch let error as NSError {
             return nil
         }
  
     }   
  
  }
  </code></pre>