【发布时间】:2020-05-02 12:58:48
【问题描述】:
我将 Elm 0.19.1 与 NoRedInk/elm-json-decode-pipeline/1.0.0
一起使用我的飞机类型是
type alias Aircraft = {name:String}
为此,我有以下解码器:
aircraftDecoder : Json.Decode.Decoder Aircraft
aircraftDecoder =
Json.Decode.succeed Aircraft
|> Json.Decode.Pipeline.required "name" Json.Decode.string
不幸的是,解码器抱怨我告诉:“BadBody”给定值的问题:(...)” 这是因为实际上我感兴趣的区域如果周围充满噪音(来自 HATEOAS api),就像这样:
{
"_embedded" : {
"aircrafts" : [ {
"name" : "AC01",
"_links" : {
"self" : {
"href" : "http://localhost:8080/aircrafts/1"
},
"aircraft" : {
"href" : "http://localhost:8080/aircrafts/1"
}
}
}, {
"name" : "AC01",
"_links" : {
"self" : {
"href" : "http://localhost:8080/aircrafts/2"
},
"aircraft" : {
"href" : "http://localhost:8080/aircrafts/2"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/aircrafts{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:8080/profile/aircrafts"
}
},
"page" : {
"size" : 20,
"totalElements" : 4,
"totalPages" : 1,
"number" : 0
}
}
如何更改代码并继续使用管道,以免解码器被所有这些噪音迷失?
我听说过一些关于使用 Json.Decode.at 的信息,但文档不够好,无法让我得到正确的代码。
【问题讨论】:
标签: json pipeline elm hateoas decoder