1

I'm getting JSON data with different data types. I want to convert a string '22' into integer 22.

I have this code: jData["ID"]

I have tried: let id = jData["ID"]! as Int

but it gave me an error

EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT,subcode=0xdefe)

Can someone please solve my problem...

Thanks

2
  • let id = ((jData["ID"] as? String) ?? "0").toInt() ?? 0 Commented Nov 3, 2014 at 21:40
  • YESS this one worked, Thanks @vacawama Commented Nov 4, 2014 at 13:45

1 Answer 1

1

Pass jData["ID"] as string and use toInt():

let id = String(jData["ID"]).toInt()
Sign up to request clarification or add additional context in comments.

1 Comment

I'v tried that it gives me error: 'AnyObject' does not have a member named 'toInt()'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.