我需要解析没有严格结构的 json API 响应:
{
response: { /* any object here */ }
}
怎么可能写出parseResponse
哪些可以解析(或为其选择解析器)以供以后使用?
我的最后一次尝试如下。我不喜欢它,因为它不允许像 Aeson 那样选择响应类型decode
。
data APIResponse =
APIResponse { response :: Value } deriving (Show,Generic)
instance FromJSON APIResponse
parseResponse :: BC.ByteString -> Either String Value
parseResponse resp =
case eitherDecode . BLC.fromStrict $ resp of
Right x -> Right $ response x
Left msg -> Left msg