我有一个 Spock 应用程序,其中有:
post "/test" $ do
a <- jsonBody'
text "test"
它抛出一个异常:
• Ambiguous type variable ‘a0’ arising from a use of ‘jsonBody'’
prevents the constraint ‘(Aeson.FromJSON a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Aeson.FromJSON Aeson.DotNetTime
因此我尝试像这样解决它:
post "/test" $ do
a <- jsonBody' :: Aeson.Object
text "test"
但没有运气:
• Couldn't match type ‘ActionCtxT
() (WebStateM () MySession MyAppState) ()’
with ‘unordered-containers-0.2.8.0:Data.HashMap.Base.HashMap
T.Text b0’
Expected type: hvect-0.4.0.0:Data.HVect.HVectElim
'[] (SpockActionCtx () () MySession MyAppState ())
Actual type: unordered-containers-0.2.8.0:Data.HashMap.Base.HashMap
T.Text b0
如何解决?
更新:
这不能解决问题:
a <- jsonBody' :: Aeson.Object
--a :: Aeson.Object <- jsonBody'
let b = show a -- using a
text "fdsfd"