Haskell Aeson 如何解析键值与列表值?
Haskell Aeson how to parse key with list value?
如果我用
解析“exchangeAgreements”
fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("exchangeAgreements" :: Data.Text.Text)) myobject) :: Object
它returns一个交换协议作为一个对象就好了
但如果我这样做
fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: Object
它returnsNothing
{
"exchangeAgreements": {
"NYSE_EXCHANGE_AGREEMENT": "ACCEPTED",
"NASDAQ_EXCHANGE_AGREEMENT": "ACCEPTED",
"OPRA_EXCHANGE_AGREEMENT": "ACCEPTED"
},
"accounts": [
{
"accountId": "123",
"displayName": "myname",
"accountCdDomainId": "12345",
"company": "AMER",
"segment": "ADVNCED",
"acl": "ABCD123",
"authorizations": {
"apex": false,
"levelTwoQuotes": false,
"stockTrading": true,
"marginTrading": true,
"streamingNews": false,
"optionTradingLevel": "COVERED",
"streamerAccess": true,
"advancedMargin": true,
"scottradeAccount": false
}
}
]
}
我需要做哪些不同的事情才能解析“帐户”?
我意识到我只需要把
[Object]
而不是 Object
作为类型
fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: [Object]
如果我用
解析“exchangeAgreements”fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("exchangeAgreements" :: Data.Text.Text)) myobject) :: Object
它returns一个交换协议作为一个对象就好了
但如果我这样做
fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: Object
它returnsNothing
{
"exchangeAgreements": {
"NYSE_EXCHANGE_AGREEMENT": "ACCEPTED",
"NASDAQ_EXCHANGE_AGREEMENT": "ACCEPTED",
"OPRA_EXCHANGE_AGREEMENT": "ACCEPTED"
},
"accounts": [
{
"accountId": "123",
"displayName": "myname",
"accountCdDomainId": "12345",
"company": "AMER",
"segment": "ADVNCED",
"acl": "ABCD123",
"authorizations": {
"apex": false,
"levelTwoQuotes": false,
"stockTrading": true,
"marginTrading": true,
"streamingNews": false,
"optionTradingLevel": "COVERED",
"streamerAccess": true,
"advancedMargin": true,
"scottradeAccount": false
}
}
]
}
我需要做哪些不同的事情才能解析“帐户”?
我意识到我只需要把
[Object]
而不是 Object
作为类型
fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: [Object]