【问题标题】:Unicode Char is not mapped by ObjectMapper correctly for a String propertyUnicode Char 没有被 ObjectMapper 正确映射为 String 属性
【发布时间】:2017-03-16 10:59:39
【问题描述】:

ObjectMapper 转换以下 JSON 字符串不正确。对于某些第二个 unicode char 之后的整个字符串在映射后被剪切。 \U33a1 代表 m2。

text = "Bitte geben Sie Ihre vermietete Fl\U00e4che (\U33a1) an.";


override func mapping(map: Map) {
    super.mapping(map: map)
    hintText = map["hintText"]
    inputType <- (map["inputType"],inputTypeTransformer)
    value <- map["value"]
    capitalizeFirstLetter <- map["capitalizeFirstLetter"]
    maxLength <- map["maxLength"]
    readOnly <- map["readOnly"]
}

映射hintText后得到值“Vermietete Fläche(”

除了这个 unicode 字符之外,所有其他的德语重音字符都被正确保存。

【问题讨论】:

  • 我怀疑问题出现在之前将对象传递给映射器
  • 其实Json字典的值是正确的

标签: ios swift unicode objectmapper


【解决方案1】:

我不是 unicodes 的大师,但似乎 swift 不知道这种格式。

我认为,您需要将它们转换为 swift 新格式。 link

var text = "Bitte geben \u{24} Sie Ihre vermieteteFl\u{00e4}che (\u{33a1}) an."; // Bitte geben $ Sie Ihre vermieteteFläche (㎡) an.

var string:NSString = "Bitte geben Sie Ihre vermietete Fl\u{00e4}che (\u{33a1}) an."; // Bitte geben Sie Ihre vermieteteFläche (㎡) an.

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2014-10-10
    • 2021-08-15
    • 1970-01-01
    相关资源
    最近更新 更多