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

2jcobegt  于 4个月前  发布在  其他
关注(0)|答案(3)|浏览(101)

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

po tmp?.publishTime
▿ Optional

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

(lldb) po vlaue["publishTime"]
▿ Optional

  • some : 1604366464447
taor4pac

taor4pac1#

在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

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

wqnecbli2#

找到报错的问题了
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

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

pbpqsu0x3#

文件: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
}()

相关问题