내가 IO에서 JSON 구문 분석을 할 노력하고있어 : 하스켈 아이손 : IO 모나드에서 파서에서 값을받는 방법
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Simple
import Data.Aeson
import Data.Maybe (fromJust)
main :: IO()
main = do
response <- getResponseBody <$> httpJSON "http://localhost:9200" :: IO Object
name <- fromJust <$> response .: "name" :: Parser String
print "hi"
내가 오류 얻을 : 그래서
/home/nut/dev/haskell/elastic/app/Main.hs:39:11: error:
• Couldn't match type ‘Parser’ with ‘IO’
Expected type: IO String
Actual type: Parser String
• In a stmt of a 'do' block:
을 어떻게 할 json 결과에서 name
을 얻으시겠습니까?
parse :: (a -> Parser b) -> a -> Result b
parseEither :: (a -> Parser b) -> a -> Either String b
parseMaybe :: (a -> Parser b) -> a -> Maybe b
당신은 예를 들어,이 그렇다면 :
을 할 수
이 있습니다. "이름"'에서 'IO'이지만, 단지'파서 '값입니다. 나는 Aeson에 익숙하지 않지만, 당신은 (Data.Aeson.Types.parse' 또는'parseMaybe'로) 순전히 파서를 실행해야한다고 생각합니다. –