当我尝试从NSDictionary对象中读取Double值时发生错误

时间:2014-10-12 08:33:19

标签: ios swift ios8 nsdictionary

let jsonDict = NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves, error: nil) as NSDictionary
let dataDict = (jsonDict["data"] as NSDictionary).copy() as NSDictionary

NSLog("%@", dataDict)

let hp = dataDict["hp"] as Double
let pay = dataDict["pay"] as Double

NSLog的输出正是dataDict的内容,但是当谈到let hp = dataDict["hp"] as Double时,Xcode总是卡在这里:

0x1083da9c2:  nopw   %cs:(%rax,%rax) // Thread 6: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)

我怎么能解决这个问题?提前谢谢。

环境:Xcode版本6.0.1(6A317),iOS 8.0模拟器

dataDict是这样的:

{
    hp = 20090458525;
    pay = 63887638528;
}

通过以下代码解决:

var hp: Double
if let str = dataDict["hp"] as AnyObject! as String! {
    hp = NSString(string: str).doubleValue
}

0 个答案:

没有答案