I have such a Swift structure.
struct Usage { var totalData: Double var remainingTotalData: Double init(jsonData: NSData) { var jsonDict = [String: AnyObject]() do { jsonDict = try NSJSONSerialization.JSONObjectWithData(jsonData, options: []) as! [String: AnyObject] } catch { print("Error occurred parsing data: \(error)") } totalData = jsonDict["totalfup"] as! Double remainingTotalData = jsonDict["totalrem"] as! Double } }
From the API, I get the following JSON response. This is the println of the jsonDict variable.
[ "totalfup": 96.340899, "totalrem": 3548710948 ]
When I try to assign the totalfup value to the totalfup property, I get this error.
Failed to assign value of type NSTaggedPointerString 'NSNumber'
Does anyone know why? I tried changing the type of the property to float , and then the whole structure to a class, but still a problem arises.
double ios swift swift2 nsjsonserialization
Isuru Oct 23 '15 at 9:37 2015-10-23 09:37
source share