KakaJSON
KakaJSON copied to clipboard
NSNumber mapping error
let json: Array<Dictionary<String, Any>> = [ [
"name": "KakaJSON",
"id" : NSNumber(6664714503134970889),
"url": "https://github.com/kakaopensource/KakaJSON"
] ,
[
"name": "KakaJSON",
"id" : 6664714503134970881,
"url": "https://github.com/kakaopensource/KakaJSON"
]]
let repo: [Repo] = json.kj.modelArray(type: Repo.self) as! [Repo]
for item in repo {
print(item.id)
}
after mapping, first item is 6664714503134970880, second item is right
// digit
if let digitType = type as? DigitValue.Type {
return Double("\(decimal)")
.flatMap { NSNumber(value: $0) }
.flatMap { digitType.init(truncating: $0) }
}
Double("(decimal)") change to double , lost last number
把 NSNumber(value: $0)的 $0转为longlong就没问题了
把 NSNumber(value: $0)的 $0转为longlong就没问题了
// IntType
if let intType = type as? IntegerValue.Type {
return Int("\(decimal)")
.flatMap { NSNumber(value: $0) }
.flatMap { intType.init(truncating: $0) }
}
我是这样改的, Int类型单独处理,自己fork一份改了