给定一个超过 8 个字段的对象,如何对其进行解码。
检查文档最多可得到 object8 。不知道如何扩展它以覆盖其他领域。我的对象包含 18 个字段。
最佳答案
尝试看看这个包 Json-Decode-Extra特别是 apply
和 (|:)
函数。
例如解码对象,例如
type alias Location =
{ id : Int
, name : String
, address : String
, city : String
, state : String
}
您可以使用构建解码器
locationDecoder : Decoder Location
locationDecoder =
succeed Location
|: ("id" := int)
|: ("name" := string)
|: ("address" := string)
|: ("city" := string)
|: ("state" := string)
关于elm - Elm 中解码超过 8 个字段的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35204503/