Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSNumber mapping error #46

Open
zhuangxq opened this issue May 15, 2020 · 3 comments
Open

NSNumber mapping error #46

zhuangxq opened this issue May 15, 2020 · 3 comments

Comments

@zhuangxq
Copy link

zhuangxq commented May 15, 2020

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

@zhuangxq
Copy link
Author

    // 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

@454961172
Copy link

把 NSNumber(value: $0)的 $0转为longlong就没问题了

@zhuangxq
Copy link
Author

zhuangxq commented Jan 15, 2021

把 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一份改了

WIIILee added a commit to WIIILee/KakaJSON that referenced this issue Nov 25, 2022
WIIILee added a commit to WIIILee/KakaJSON that referenced this issue Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants