하스켈 아이손 JSON 라이브러리 ByteString 문제
한 Data.ByteString.Lazy.Internal.ByteString
에 decode
입니다 변환하는 기능이나 해결 방법을 찾는 데 문제가 다음과 같은 설명이있어
:
를decode :: FromJSON a => bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString -> Maybe a
Data.ByteString.Lazy.Char8에서 pack 함수를 사용해 보았지만 다른 ByteString을 반환합니다. 어느 누구가이 문제를 해결할 수 있는지 알고 있습니까?
import Data.Aeson
import Data.Text
import Control.Applicative
import Control.Monad (mzero)
import qualified Data.ByteString.Lazy.Internal as BLI
import qualified Data.ByteString.Lazy.Char8 as BSL
data Person = Person
{ name :: Text
, age :: Int
} deriving Show
instance FromJSON Person where
parseJSON (Object v) = Person <$>
v .: (pack "name") <*>
v .: (pack "age")
parseJSON _ = mzero
내가 decode (BSL.pack "{\"name\":\"Joe\",\"age\":12}") :: Maybe Person
를 사용하여 시도하고 다음과 같은 오류 메시지가 있어요 :
Couldn't match expected type `bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString'
with actual type `BSL.ByteString'
In the return type of a call of `BSL.pack'
In the first argument of `decode', namely
`(BSL.pack "{\"name\":\"Joe\",\"age\":12}")'
In the expression:
decode (BSL.pack "{\"name\":\"Joe\",\"age\":12}") :: Maybe Person
도움말을
다음은 내가 일하고 있어요 예입니다!
여러 버전의 바이트 테스트를 설치 했습니까? 확인을 위해'ghc-pkg list bytestring'을 실행 해보십시오. – bennofs
목록에 bytestring-0.10.0.2와 bytestring-.10.4.0의 두 항목이 표시됩니다. 이로 인해 문제가 발생합니까? 나는 위의 코드로 놀고있을 때 이전에 GHCI 링크 오류가 있음을 알고있다. – MathanMV
예, 작업을하기 위해 bytestring-10.4.0의 등록을 취소해야했습니다. – MathanMV