I am trying to use a string I am getting from a database as JSON using swift. I have tried to convert the string to a data object and then use JSONSerialization, but the results always come back nil.
Here is a sample of my code:
var string = "{Param1: \"Value\", Param2: \"value2\", Param3: \"value3\"}"
let data = (reducedOptionsString as NSString).dataUsingEncoding(NSUTF8StringEncoding)
if let d = data{
var err : NSErrorPointer = nil
let parsedObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(d, options: NSJSONReadingOptions.MutableLeaves, error: err)
if let dict = parsedObject as? Dictionary<String, AnyObject>{
...
}
}
For some reason parsedObject always comes back as nil
Does anyone know what I might be missing to convert my string data to a JSON object that I can use?
stringis not used andreducedOptionsStringis undefined. I guess they are the same.