我收到此错误:
No instance for (Show (ClientM Bittrex)) arising from a use of ‘print
构建以下代码时:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.HTTP.Client (newManager, defaultManagerSettings)
import Servant.API
import Servant.Client
data Bittrex = Bittrex
{ success :: Bool,
message :: String,
result :: Inner
} deriving (Generic, Show)
instance FromJSON Bittrex
instance ToJSON Bittrex
data Inner = Inner
{ bid :: Float,
ask :: Float,
last :: Float
} deriving (Generic, Show)
instance FromJSON Inner
instance ToJSON Inner
--------------------------------------------------------------------------------
-- https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC
type BittrexAPI = "api" :> "v1.1" :> "public" :> "getticker?market=BTC-LTC" :> Get '[JSON] Bittrex
-----------------------------------------------------------------------------
bittrexAPI :: Proxy BittrexAPI
bittrexAPI = Proxy
bittrex = client bittrexAPI
main :: IO ()
main = do
manager <- newManager defaultManagerSettings
res <- runClientM bittrex (ClientEnv manager (BaseUrl Http "bittrex.com" 80 ""))
case res of
Left err -> putStrLn $ "Error: " ++ show err
Right test -> do
print $ bittrex
我知道问题来自于我有一个嵌入式JSON的JSON响应。我不确定如何纠正这个或更重要的是为什么会发生这种情况。请求链接为https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC