HandyJSON icon indicating copy to clipboard operation
HandyJSON copied to clipboard

崩溃??? 系统切换到阿拉伯语网络返回的数字为啥解析后,也成阿拉伯语了呢????

Open kangbaobao opened this issue 5 years ago • 3 comments

系统切换到阿拉伯语网络返回的数字为啥解析后,也成阿拉伯语了呢????

po tmp?.publishTime ▿ Optional<String>

  • some : "١٦٠٤٣٦٦٤٦٤٤٤٧"

(lldb) po vlaue["publishTime"] ▿ Optional<Any>

  • some : 1604366464447

kangbaobao avatar Nov 18 '20 12:11 kangbaobao

在ExtendCustomType.swift文件中170行代码: if let rawValue = getRawValueFrom(dict: _dict, property: propertyDetail, mapper: mapper) { if let convertedValue = convertValue(rawValue: rawValue, property: propertyDetail, mapper: mapper) { assignProperty(convertedValue: convertedValue, instance: instance, property: propertyDetail) continue } }

po rawValue 4 (lldb) po convertedValue ▿ Optional<String>

  • some : "٤" 多么诡异的代码????

kangbaobao avatar Nov 18 '20 13:11 kangbaobao

找到报错的问题了 extension String: _BuiltInBasicType { static func _transform(from object: Any) -> String? { switch object { case let str as String: return str case let num as NSNumber: // Boolean Type Inside if NSStringFromClass(type(of: num)) == "__NSCFBoolean" { if num.boolValue { return "true" } else { return "false" } } return formatter.string(from: num) case _ as NSNull: return nil default: return "(object)" } } } 就是这句 formatter.string(from: num) 在阿拉伯语中num传入数字,会返回阿拉伯语 (lldb) po num 1552470694000 (lldb) po formatter.string(from: num) ▿ Optional<String>

  • some : "١٥٥٢٤٧٠٦٩٤٠٠٠"

kangbaobao avatar Nov 19 '20 01:11 kangbaobao

文件:BuiltInBasicType fileprivate let formatter: NumberFormatter = { let formatter = NumberFormatter() formatter.usesGroupingSeparator = false formatter.numberStyle = .decimal formatter.maximumFractionDigits = 16 //强行使用英语模式 formatter.locale = NSLocale(localeIdentifier: "en_US") as Locale return formatter }()

KevinXinSuiLu avatar Apr 06 '23 08:04 KevinXinSuiLu