这有效:
λ decode "[\"one\", \"two\"]" :: Maybe [Text]
Just ["one","two"]
这有效:
λ decode "[1, 2]" :: Maybe [Int]
Just [1,2]
这是完全有效的 JSON,但我无法使其工作:
λ decode "[\"one\", 2]" :: Maybe [Text]
Nothing
甚至:
λ decode "[2]" :: Maybe [Text]
Nothing
我想说服最后一个给我:
Just ["one","2"]
Just ["2"]
但我无法看到将 Aeson 的手臂扭到看到它想将其视为数字作为字符串的东西。
更新:
λ decode "[1, \"2\"]" :: Maybe Array
Just (fromList [Number 1.0,String "2"])
我想这样会好一些。我仍然希望我能让 Aeson 将所有内容强制转换为字符串,但我想我可以使用它。