在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:elm/json开源软件地址:https://github.com/elm/json开源编程语言:Elm 73.8%开源软件介绍:JSON in ElmThis package helps you convert between Elm values and JSON values. This package is usually used alongside ExampleHave you seen this causes of death table? Did you know that in 2002, war accounted for 0.3% of global deaths whereas road traffic accidents accounted for 2.09% and diarrhea accounted for 3.15%? The table is interesting, but say we want to visualize this data in a nicer way. We will need some way to get the cause-of-death data from our server, so we create encoders and decoders: module Cause exposing (Cause, encode, decoder)
import Json.Decode as D
import Json.Encode as E
-- CAUSE OF DEATH
type alias Cause =
{ name : String
, percent : Float
, per100k : Float
}
-- ENCODE
encode : Cause -> E.Value
encode cause =
E.object
[ ("name", E.string cause.name)
, ("percent", E.float cause.percent)
, ("per100k", E.float cause.per100k)
]
-- DECODER
decoder : D.Decoder Cause
decoder =
D.map3 Cause
(D.field "name" D.string)
(D.field "percent" D.float)
(D.field "per100k" D.float) Now in some other code we can use Point is, the goal should be:
So say you decide to make the Future PlansIt is easy to get focused on how to optimize the use of JSON, but I think this is missing the bigger picture. Instead, I would like to head towards this vision of data interchange. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论