Json.Decode.{} 是什么意思?点花括号部分
What does Json.Decode.{} mean? The dot curly braces part
我正在尝试学习 ReasonML 并遵循 bs-json 的示例,我们可以将原始 json 解码为如下类型:
type point = {
x: float,
y: float
};
module Decode = {
let point = json =>
Json.Decode.{
x: json |> field("x", float),
y: json |> field("y", float)
};
}
我对这个 Json.Decode.{ ... }
是什么感到有点困惑。我知道我们可以使用 .()
点括号将范围打开到模块中,但我以前没有见过这个点花括号。
这几乎是同一件事,Json.Decode
在 {}
的范围内打开,它像往常一样定义了一条记录。本质上只是 Json.Decode.({ .. })
.
的缩写
编辑:我刚刚在 bs-json
s README 中添加了注释,就在 the example 下方,以解释此语法。
我正在尝试学习 ReasonML 并遵循 bs-json 的示例,我们可以将原始 json 解码为如下类型:
type point = {
x: float,
y: float
};
module Decode = {
let point = json =>
Json.Decode.{
x: json |> field("x", float),
y: json |> field("y", float)
};
}
我对这个 Json.Decode.{ ... }
是什么感到有点困惑。我知道我们可以使用 .()
点括号将范围打开到模块中,但我以前没有见过这个点花括号。
这几乎是同一件事,Json.Decode
在 {}
的范围内打开,它像往常一样定义了一条记录。本质上只是 Json.Decode.({ .. })
.
编辑:我刚刚在 bs-json
s README 中添加了注释,就在 the example 下方,以解释此语法。