I am new to Xcode and Swift, and I am trying to serialize JSON data from a url using the code below and get the error
'NSJSONReadingOptions' is not convertible to 'NSJSONWritingOptions'
on the line
var jsonResult = NSJSONSerialization.dataWithJSONObject(data, options: NSJSONReadingOptions.MutableContainers, error: nil)!
I cannot see my error, from online sources others use the same code and its works?
let task = session.dataTaskWithURL(loginUrl!, completionHandler: { (data, response, error) -> Void in
if error != nil {
}else {
var jsonResult = NSJSONSerialization.dataWithJSONObject(data, options: NSJSONReadingOptions.MutableContainers, error: nil)!
println(jsonResult)
}
})
task.resume();
dataWithJSONObjectwhich is used for serializing array/dictionary into JSON stored in aNSDataobject. But you want to callJSONObjectWithData, to deserialize JSON stored inNSDatainto an array/dictionary. TheNSJSONReadingOptionsis used withJSONObjectWithData. So, the problem isn't theNSJSONReadingOptions, but rather the fact that you calleddataWithJSONObjectinstead ofJSONObjectWithData.