【问题标题】:How to map json object to string while using <-map["xx"]使用 <-map["xx"] 时如何将 json 对象映射到字符串
【发布时间】:2019-05-29 10:51:25
【问题描述】:

我需要在映射时将 json 对象转换为字符串,但 fromJSON 始终为零。

我提供了一段代码,我认为我不应该在value 中得到零。我想我应该得到“a.b”下的json

   func mapping(map: Map) {
        b <- (map["a.b"], TransformOf<String, String>(fromJSON: { value in print("json \(value)"); return String(value) }, toJSON: { $0.map { String($0) } }))
    }

我试图从中映射的 json 看起来像这样

{
"a" : {
       "b" : { ..... } <- this is the piece I need as string
      }
}

【问题讨论】:

    标签: swift objectmapper


    【解决方案1】:

    你可能想看看

    Using JSON with custom types

    其中包含一个使用 Swift Codable 转换 JSON 的工作场所

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多