请评论如何在 ReasonML 中解码 GeoJson 文件?我尝试在解码器中解码没有“字段纬度和经度”的坐标,但我找不到任何信息如何解析 JSON 文件中的字段坐标。
GeoJson 文件
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
131.469670264,
33.3158712032
]
},
"properties": {
"index": 0,
"alias": "海地獄-別府市",
"name": "Umi-Jigoku",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/7T1aXG9Q3CAtEbwqFm3Nlw/o.jpg"
}
ReasonML 中的 JsonDecoder (bs-json)
[@genType]
type properties = {
index: int,
alias: string,
name: string,
image_url: string,
geometry: coordinates,
}
and coordinates = {
latitude: float,
longitude: float,
};
let places = "../json/alljapan.json";
module Decode = {
let coordinates = json =>
Json.Decode.{
latitude: json |> field("latitude", float),
longitude: json |> field("longitude", float),
};
let properties = json =>
Json.Decode.{
index: json |> field("index", int),
alias: json |> field("alias", string),
name: json |> field("name", string),
image_url: json |> field("image_url", string),
geometry: json |> field("geometry", coordinates),
};
};
let line = places |> Json.parseOrRaise |> Decode.line;