如何在使用<-map [“ xx”]时将json对象映射到字符串

时间:2019-05-29 10:51:25

标签: swift objectmapper

我需要在映射时将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
      }
}

1 个答案:

答案 0 :(得分:0)

您可能想看看

Using JSON with custom types

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