6
一直試圖讓這對雨燕2.0工作,錯誤說:使用NSSerialization.datawithJSON斯威夫特2
類型NSJSONWritingOptions不能遵守協議NilLiteralConvertible
在var options = prettyPrinted...
:
func JSONStringify(value: AnyObject,prettyPrinted:Bool = false) -> String {
var options = prettyPrinted ? NSJSONWritingOptions.PrettyPrinted : nil
if NSJSONSerialization.isValidJSONObject(value) {
do{
let data = try NSJSONSerialization.dataWithJSONObject(value, options: options)
if let string = NSString(data: data, encoding: NSUTF8StringEncoding) {
return string as String
}
} catch {
}
}
return ""
}