有人可以解释我如何使用json解析器和AttoParsec的解析函数生成fromList [英] Could someone explain how I am generating a fromList using a json parser with the parse function from AttoParsec

查看:116
本文介绍了有人可以解释我如何使用json解析器和AttoParsec的解析函数生成fromList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,如果我使用json解析器解析json数据,我会返回json类型。当然,除非数据不正确。但是,我希望解析失败。



这些都是用ghci完成的。

 > test<  - (parseUrlhttps://pkg.cudaops.com/cgi-bin/qaLinkEditor.cgi?json=1)::(IO(请求IO))
> nManager< - newManager
> catch< - httpLbsRedirect test nManager
> let catchChunks = toChunks $ responseBody catch
> let flatChunks = Data.ByteString.concat catchChunks
> let parsed = parse json flatChunks
>:t parsed
> parsed :: Data.Attoparsec.Result Value

结果相当大,下面是我写出来的解析开始的一部分



完成\\ \\ nObject(fromList [(name,Stringversions),(products,Object(fromList [(BCC Admin,Object(fromList [(available,Array(fromList [String ...



我如何得到fromList?它说Object(fromList [(available,Array ...,I expectedObject(Array [available ,阵......我错了使用解析?我只是误解了分析是如何工作的,它做了它应该做的事情,我的期望错了吗?

数组如何打印。约定是 Show 实例应该提供有效的Haskell代码来重新创建值。


My understanding is that if I use the json parser with parse on json data, I would get json types back. Unless,of course, the data is mal-formed. But then I would expect a failed parse.

This is all done in ghci.

>test <- (parseUrl "https://pkg.cudaops.com/cgi-bin/qaLinkEditor.cgi?json=1") :: (IO (Request IO))
>nManager <- newManager
>catch <- httpLbsRedirect test nManager
>let catchChunks = toChunks $ responseBody catch
>let flatChunks = Data.ByteString.concat catchChunks
>let parsed = parse json flatChunks
>:t parsed
>parsed :: Data.Attoparsec.Result Value

The result is rather large, Here's part of the beginning of parsed that I wrote out to file

Done "\n" Object (fromList [("name",String "versions"),("products",Object (fromList [("BCC Admin",Object (fromList [("available",Array (fromList [String ..."

How am I getting fromList? Where it says"Object (fromList [("available",Array... ", I expected "Object(Array ["available",Array ..." Am I misusing parse? Could I just be misunderstanding how parse works, it did what it was supposed to do and my expectations were wrong?

解决方案

That's just how arrays print. The convention is that Show instances should give valid Haskell code that recreates the value.

这篇关于有人可以解释我如何使用json解析器和AttoParsec的解析函数生成fromList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆