NSJSONSerialization来自Swift字典的json数据,其中包含struct作为值

NSJSONSerialization来自Swift字典的json数据,其中包含struct作为值,swift,ios8,nsjsonserialization,Swift,Ios8,Nsjsonserialization,我正在尝试使用NSJSONSerialization将swift字典(字符串作为键,结构作为值)转换为json数据。但我得到了这个错误: Cannot invoke 'dataWithJSONObject' with an argument list of type'([String : Vik.Version], options: NSJSONWritingOptions, error: nil) 有什么我遗漏的吗。任何帮助都将不胜感激 谢谢 下面是我的代码 final class Vik:

我正在尝试使用NSJSONSerialization将swift字典(字符串作为键,结构作为值)转换为json数据。但我得到了这个错误:

Cannot invoke 'dataWithJSONObject' with an argument list of type'([String : Vik.Version], options: NSJSONWritingOptions, error: nil)
有什么我遗漏的吗。任何帮助都将不胜感激

谢谢

下面是我的代码

final class Vik: NSObject {

    private struct Version {
       private var name: String
       private var filesToAdd = [String]()
       private var filesToRemove = [String]()

       init(name: String, filesToAdd: [String]?, filesToRemove: [String]?) {
          self.name = name

          if let filesToAdd = filesToAdd {
            self.filesToAdd = filesToAdd
          }

          if let filesToRemove = filesToRemove {
            self.filesToRemove = filesToRemove
          }
       }
    }
    ......
    ......
    ......

    private var changeLogDict = [String : Version]()

    private func addToDirectory() {
       .......
       .......
       let jsonData = NSJSONSerialization.dataWithJSONObject(self.changeLogDict, options: NSJSONWritingOptions.PrettyPrinted, error: nil)
       .......
       .......
    }

}

我想出来了。NSJSONSerialization.dataWithJSON方法采用“AnyObject”数据类型。Swift dictionary是一个结构而不是对象,因此它是一个结构。下面的行编译得很好

let jsonData = NSJSONSerialization.dataWithJSONObject(self.changeLogDict as NSDictionary, options: NSJSONWritingOptions.PrettyPrinted, error: nil)

我想出来了。NSJSONSerialization.dataWithJSON方法采用“AnyObject”数据类型。Swift dictionary是一个结构而不是对象,因此它是一个结构。下面的行编译得很好

let jsonData = NSJSONSerialization.dataWithJSONObject(self.changeLogDict as NSDictionary, options: NSJSONWritingOptions.PrettyPrinted, error: nil)

我想出来了。NSJSONSerialization.dataWithJSON方法采用“AnyObject”数据类型。Swift dictionary是一个结构而不是对象,因此它是一个结构。下面的行编译得很好

let jsonData = NSJSONSerialization.dataWithJSONObject(self.changeLogDict as NSDictionary, options: NSJSONWritingOptions.PrettyPrinted, error: nil)

我想出来了。NSJSONSerialization.dataWithJSON方法采用“AnyObject”数据类型。Swift dictionary是一个结构而不是对象,因此它是一个结构。下面的行编译得很好

let jsonData = NSJSONSerialization.dataWithJSONObject(self.changeLogDict as NSDictionary, options: NSJSONWritingOptions.PrettyPrinted, error: nil)