elm - Elm 中解码超过 8 个字段的对象

标签 elm

给定一个超过 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/

相关文章:

dom - 在 Elm 更新中重新排序项目时如何获取要更新的输入值

f# - 使用 Fable-Elmish 上传文件

elm - 我找不到模块 'Graphics.Element'

elm - 是否有类似 elm-package.json 的 npm 脚本之类的东西?

random - 在 Elm 中生成随机数所需的最少代码是多少?

parallel-processing - 如何在Elm中合并多个效果?

Elm:获取图像的大小

elm - 筛选,也许, Elm

list - 如何 List.sum 一个列表(也许是 float )?

typeerror - elm-lang 错误 `(==) is expecting the right side to be a:`