将JSON直接从Aeson编码输出写为lazy ByteString,而不转换为String

时间:2016-04-17 03:49:46

标签: json haskell aeson lazy-io

目前,我正在使用类似的东西将JSON内容(def create @casting = Casting.new(casting_params) @casting.models_booked = 0 @casting.save link = LinkModelAndCasting.new link.client_id = @casting.id link.save # link_model_and_casting = LinkModelAndCasting.new(:casting_id => @casting.id) # link_model_and_casting.save respond_to do |format| if @casting.id format.html { redirect_to @casting, notice: 'Casting was successfully created.' } format.json { render :show, status: :created, location: @casting } else format.html { render :new } format.json { render json: @casting.errors, status: :unprocessable_entity } end end end )写入文件(my_json):

my_output_filepath

这很有效,但我想知道是否有必要将import Data.Aeson.Encode.Pretty import qualified Data.ByteString.Lazy.UTF8 as U writeFile my_output_filepath $ U.toString $ encodePretty my_json 返回的ByteString转换为encodePretty,然后再将其写入文件,或者如果它导致性能损失。

我看到String的{​​{3}}接受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变体与ByteString互操作?

0 个答案:

没有答案