【发布时间】:2016-03-04 16:59:04
【问题描述】:
我有这种情况
-- this is in post.elm
type alias Model =
{ img : String
, text : String
, source : String
, date : String
, comments : Comments.Model
}
-- this is in comments.elm
type alias Model =
List Comment.Model
-- this is in comment.elm
type alias Model =
{ text : String
, date : String
}
我正在尝试解析这样形成的 JSON
{
"posts": [{
"img": "img 1",
"text": "text 1",
"source": "source 1",
"date": "date 1",
"comments": [{
"text": "comment text 1 1",
"date": "comment date 1 1"
}]
}
}
这是我的Decoder
decoder : Decoder Post.Model
decoder =
Decode.object5
Post.Model
("img" := Decode.string)
("text" := Decode.string)
("source" := Decode.string)
("date" := Decode.string)
("comments" := Decode.list Comments.Model)
decoderColl : Decoder Model
decoderColl =
Decode.object1
identity
("posts" := Decode.list decoder)
它不起作用,我得到了
Comments不会暴露Model。
如何公开type alias?
如何为我的示例设置Decoder?
【问题讨论】: