Ich habe diese Daten mit http://jsonapi.org/ Format:Elm: Wie man Daten von JSON API dekodieren
{
"data": [
{
"type": "prospect",
"id": "1",
"attributes": {
"provider_user_id": "1",
"provider": "facebook",
"name": "Julia",
"invitation_id": 25
}
},
{
"type": "prospect",
"id": "2",
"attributes": {
"provider_user_id": "2",
"provider": "facebook",
"name": "Sam",
"invitation_id": 23
}
}
]
}
ich meine Modelle wie haben:
type alias Model = {
id: Int,
invitation: Int,
name: String,
provider: String,
provider_user_id: Int
}
type alias Collection = List Model
ich die json in eine Sammlung entschlüsseln möchten, aber ich weiß nicht wie.
fetchAll: Effects Actions.Action
fetchAll =
Http.get decoder (Http.url prospectsUrl [])
|> Task.toResult
|> Task.map Actions.FetchSuccess
|> Effects.task
decoder: Json.Decode.Decoder Collection
decoder =
?
Wie implementiere ich Decoder? Danke
Ich könnte nützlich sein, wenn Sie auch erläutert, wie Sie einen Wert in ein Ergebnis zuordnen. –
OP nur nach der Implementierung des Decoders gefragt. Um das Ergebnis zu erhalten, rufen Sie 'Json.Decode.decodeString' oder' decodeValue' auf. – mgold
Decode.object5 ist jetzt Decode.map5 – madnight