简体   繁体   English

Data.Aeson 导入密钥

[英]Data.Aeson import Key

I have the below code for parsing Int from an object.我有以下代码用于从 object 解析 Int。 But unable to find the correct import for Key .但无法找到Key的正确导入。

parseInt :: Object -> Key -> Parser Int
parseInt v field =
  asum
    [ v .: field,
      do
        s <- v .: field
        case readMaybe s :: Maybe Int of
          Nothing -> fail "not a number"
          Just x -> return x
    ]

I have tried我努力了

import Data.Aeson

and

import Data.Aeson.Types

But get the error但是得到错误

    Not in scope: type constructor or class ‘Key’
    A data constructor of that name is in scope; did you mean DataKinds?

What should be the correct import for Key in my function?我的 function 中的Key的正确导入应该是什么?

It looks like you're writing code targeting aeson 2.x, but that you have aeson 1.x installed.看起来您正在编写针对aeson 2.x 的代码,但您安装了aeson Either upgrade (recommended), or use Text in place of Key there.要么升级(推荐),要么在此处使用Text代替Key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM