我正在努力为链接列表编写解码器:
listOfLinksDecoder : Decoder (List JsonLink)
listOfLinksDecoder =
Decode.map (List JsonLink)
(field "Links" <| Decode.list linkDecoder)
错误:
Decode.map (List JsonLink)
无法找到变量
List
请注意,我已成功为单个链接编写解码器:
linkDecoder : Decoder JsonLink
linkDecoder =
Decode.map6 JsonLink
(field "Profile" profileDecoder)
(field "Title" Decode.string)
(field "Url" Decode.string)
(field "ContentType" Decode.string)
(field "Topics" <| Decode.list topicDecoder)
(field "IsFeatured" Decode.bool)
请注意,我尝试搜索this documentation。但是,我仍然无法找到我的案例。
附录
topicLinks : Id -> Topic -> ContentType -> (Result Http.Error (List JsonLink) -> msg) -> Cmd msg
topicLinks providerId topic contentType msg =
let
url =
baseUrl ++ (getId providerId) ++ "/" ++ "topiclinks"
body =
encodeId providerId |> Http.jsonBody
request =
Http.post url body linksDecoder
in
Http.send msg request
答案 0 :(得分:3)
您不需要映射,您可以这样做:
listOfLinksDecoder : Decoder (List JsonLink)
listOfLinksDecoder =
field "Links" <| Decode.list linkDecoder
另请注意,Cannot find variable List
错误是因为List
是一种类型,而不是构造函数/函数。