直接从Aeson encode输出将JSON作为lazy ByteString写入文件,而不转换为字符串
目前,我正在使用类似的方法将JSON内容(直接从Aeson encode输出将JSON作为lazy ByteString写入文件,而不转换为字符串,json,haskell,aeson,lazy-io,Json,Haskell,Aeson,Lazy Io,目前,我正在使用类似的方法将JSON内容(my_JSON)写入一个文件(my_output\u filepath): 这是可行的,但我想知道是否有必要在将(encodePretty)返回的ByteString转换为字符串,然后再将其写入文件,或者是否会导致性能损失 我看到一个writeFile,它接受一个ByteString作为输入。但是,当我尝试使用它时,会出现以下错误: Couldn't match expected type ‘B.ByteString’ with
my_JSON
)写入一个文件(my_output\u filepath
):
这是可行的,但我想知道是否有必要在将(encodePretty
)返回的ByteString
转换为字符串
,然后再将其写入文件,或者是否会导致性能损失
我看到一个writeFile
,它接受一个ByteString
作为输入。但是,当我尝试使用它时,会出现以下错误:
Couldn't match expected type ‘B.ByteString’
with actual type ‘U.ByteString’
NB: ‘B.ByteString’ is defined in ‘Data.ByteString.Internal’
‘U.ByteString’ is defined in ‘Data.ByteString.Lazy.Internal’
有没有办法让
的Lazy
变体通过testring
与writeFile
进行互操作?能否请您发布导致错误的部分源代码?我看不出strict bytestring从何而来,encodePretty
从数据返回lazy bytestring和writeFile
。bytestring.lazy
也需要lazy bytestring。可能是您正在从strict bytestring模块Data.bytestring
导入writeFile吗?确保你确实在使用你链接到的懒惰者。这还不够吗@WillSewell你是对的。哦,你能不能把你的源代码中导致错误的部分贴出来?我看不出strict bytestring从何而来,encodePretty
从数据返回lazy bytestring和writeFile
。bytestring.lazy
也需要lazy bytestring。可能是您正在从strict bytestring模块Data.bytestring
导入writeFile吗?确保你确实在使用你链接到的懒惰者。这还不够吗@WillSewell你是对的。哦。
Couldn't match expected type ‘B.ByteString’
with actual type ‘U.ByteString’
NB: ‘B.ByteString’ is defined in ‘Data.ByteString.Internal’
‘U.ByteString’ is defined in ‘Data.ByteString.Lazy.Internal’