{"action":"created","issue":{"url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/316","labels_url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/316/labels{/name}","comments_url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/316/comments","events_url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/316/events","html_url":"https://github.com/SwiftyJSON/SwiftyJSON/issues/316","id":103922471,"number":316,"title":"Handling quote-wrapped non-string values (ints, etc)","user":{"login":"endash","id":20806,"avatar_url":"https://avatars.githubusercontent.com/u/20806?v=3","gravatar_id":"","url":"https://api.github.com/users/endash","html_url":"https://github.com/endash","followers_url":"https://api.github.com/users/endash/followers","following_url":"https://api.github.com/users/endash/following{/other_user}","gists_url":"https://api.github.com/users/endash/gists{/gist_id}","starred_url":"https://api.github.com/users/endash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endash/subscriptions","organizations_url":"https://api.github.com/users/endash/orgs","repos_url":"https://api.github.com/users/endash/repos","events_url":"https://api.github.com/users/endash/events{/privacy}","received_events_url":"https://api.github.com/users/endash/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-30T13:07:54Z","updated_at":"2015-11-02T19:09:06Z","closed_at":"2015-11-02T19:09:06Z","body":"I deal with a 3rd party API where every value except for `nil` is wrapped in quotation marks, and thus gets parsed as `.String`. Using the `var int: Int?` in this case will always returns nil. The solution, currently, is to conditionally unwrap the `string` representation, and then pass that to `Int.init?` to finally get an `Int?`. This is ungainly, and probably not too rare a problem, as legacy APIs go.\r\n\r\nI propose that `var int: Int?` be modified to handle this case implicitly, by checking for a `.String` and returning the result of passing that value to `Int.init?`. This would properly align the semantics of the code with the data, for the developer, rather than the peculiarities of the original serialization.\r\n\r\n(Other types might also merit this treatment, but so far I'm only dealing with `Int`s personally)\r\n\r\nI can handle the code changes personally, depending on receptiveness/feedback."},"comment":{"url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/comments/153127224","html_url":"https://github.com/SwiftyJSON/SwiftyJSON/issues/316#issuecomment-153127224","issue_url":"https://api.github.com/repos/SwiftyJSON/SwiftyJSON/issues/316","id":153127224,"user":{"login":"zhigang1992","id":1057756,"avatar_url":"https://avatars.githubusercontent.com/u/1057756?v=3","gravatar_id":"","url":"https://api.github.com/users/zhigang1992","html_url":"https://github.com/zhigang1992","followers_url":"https://api.github.com/users/zhigang1992/followers","following_url":"https://api.github.com/users/zhigang1992/following{/other_user}","gists_url":"https://api.github.com/users/zhigang1992/gists{/gist_id}","starred_url":"https://api.github.com/users/zhigang1992/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhigang1992/subscriptions","organizations_url":"https://api.github.com/users/zhigang1992/orgs","repos_url":"https://api.github.com/users/zhigang1992/repos","events_url":"https://api.github.com/users/zhigang1992/events{/privacy}","received_events_url":"https://api.github.com/users/zhigang1992/received_events","type":"User","site_admin":false},"created_at":"2015-11-02T19:09:06Z","updated_at":"2015-11-02T19:09:06Z","body":"This should do it\r\n\r\n```swift\r\nlet j:JSON = [\"a\":\"12\"]\r\nj[\"a\"].string.flatMap({Int($0)})\r\n```\r\n\r\n:beers: "}}