xcode - Cast JSON AnyObject to Double (Swift) -
i want cast anyobject json double in swift.
let value = double(jsonresult["counter"])
not work
let value = jsonresult["counter"] as? double
not work
let value = jsonresult["counter"] as! double
not work
numbers in dictionaries(/from json) nsnumber. can use (jsonresult["counter"] as? nsnumber).doublevalue
. (the double type not class, can't anyobject.)
edit: sounds server returning data as string, {"counter": "1234"}
.
in case, can take advantage of nsstring method called doublevalue
parses string (or can use integervalue
):
if let counter = (parsejson["counter"] as? nsstring)?.doublevalue { // }
Comments
Post a Comment