代码之家  ›  专栏  ›  技术社区  ›  Ackdari

如何处理类型可能需要一段时间从/到Json进行解码或编码

  •  0
  • Ackdari  · 技术社区  · 5 年前

    我想知道对包含该类型字段的类型进行解编码的最佳/首选方法是什么 Maybe a

    假设我们有类型

    type alias SomeType =
        { someInt : Int
        , someMaybe : Maybe Float
        , someOtherInt : Int
        }
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   John F. Miller    5 年前

    最明显的解决方案是,当值为 Nothing 。如果字段不存在,则在解码时将字段设置为 没有什么 .