我正在尝试从Haskell服务器获取一些JSON数据,但我遇到了Respondeable实例,以及一般的Affjax.我已经使用Data.Argonaut.Generic.Aeson(GA)定义了EncodeJson + DecodeJson,但我无法弄清楚如何将其与Respondeable实例相匹配并且它来自响应函数.
它给了我错误"无法匹配类型外部与类型Json"但是可以重用我的decodeJson实例而不必手动创建任何其他东西吗?也许通过创建一个IsForeign实例,但使用GA.decodeJson?我只是不确定如何去做.我已经看到它是如何在https://github.com/purescript/purescript-foreign/blob/master/examples/Complex.purs手动完成的,但我有复杂的类型需要与我的Haskell JSON输出相匹配,手动完成这将是一个巨大的痛苦.
我正在使用purescript 10.7,Affjax 3.02和argonaut 2.0.0,以及argonaut-generic-codecs 5.1.0.谢谢!
testAffjax :: forall eff. Aff (ajax :: AJAX | eff) (Answer)
testAffjax = launchAff do
res <- affjax $ defaultRequest { url = "/", method = Left GET }
pure res.response
data Answer = Answer {
_answer :: String
, _isCorrect :: Boolean
, _hint :: String
}
{- PROBLEM -}
instance respondableAnswer :: Respondable Answer where
responseType = Tuple Nothing JSONResponse
fromResponse = GA.decodeJson {- Error here …Run Code Online (Sandbox Code Playgroud)