0
私は最初のElmアプリケーションを開発中です。Elm:ローカルJSONファイルをdictにデコードします
ルックアップテーブルとしてローカルのJSONファイルを使用します。このファイルは気象条件(文字列)と提案された衣服(リスト)を一致させます。
EDIT(質問を明確にする):2015年のいくつかの以前の質問に基づいて、Http.getを使用してコンテンツを取得し、次にDecode.dictを使用してDictを作成しようとしました。ローカルファイルを取り込むためにHttpモジュールを使用するのは奇妙に思えます。この方法論は、Http.send
をElmで正しく使用していますか?
また、私のようなJSONファイルで動作するデコーダの例が見つかりません。任意のポインタが評価されるだろう。
JSON
{
"male,10,overcast,light wind...": ["Winter Cap", "Light Jacket"...],
"female,30,partly cloudy...": ["Winter Cap", "Sunglasses", ...]
}
CODE
type alias ClothingDict =
Dict String List
clothingUrl: String
clothingUrl =
"./clothing.json"
getClothingDict : Cmd Msg
getClothingDict =
let
url = clothingUrl
in
Http.send SetClothing (Http.get url decodeClothingResponse)
type alias ClothingResponse =
{ clothingOptions: ClothingDict }
decodeClothingResponse : Decoder ClothingResponse
decodeClothingResponse =
Decode.dict ClothingResponse
にJSONからの文字列のリストをデコーダうデコーダであるinitのフラグとしてJSONを渡す検討? –