Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE OverloadedStrings #-}
- import Data.Aeson
- import qualified Data.ByteString.Lazy.Char8 as C
- import Control.Monad
- import Control.Applicative
- data AuctionInfo = AuctionInfo {
- realm :: Realm ,
- alliance :: Auctions ,
- horde :: Auctions ,
- neutral :: Auctions
- } deriving (Show )
- instance FromJSON AuctionInfo where
- parseJSON (Object o) = do
- r <- o .: "realm" >>= parseJSON
- a <- o .: "alliance" >>= parseJSON
- h <- o .: "horde" >>= parseJSON
- n <- o .: "neutral" >>= parseJSON
- return $ AuctionInfo r a h n
- parseJSON _ = mzero
- data Realm = Realm { name2 :: String , slug:: String} deriving (Show )
- instance FromJSON Realm where
- parseJSON (Object o) = Realm <$>
- o .: "name" <*>
- o .: "slug"
- parseJSON _ = mzero
- data Auctions = Auctions {auctions :: [Auc]} deriving (Show)
- instance FromJSON Auctions where
- parseJSON (Object o ) = Auctions <$> o.: "auctions"
- parseJSON _ = mzero
- data Auc = Auc {
- auc :: Integer,
- itme :: Int,
- owner :: String,
- bid :: Integer,
- buyout ::Integer,
- quantity :: Int,
- timeLeft :: String,
- rand :: Integer,
- seed :: Integer
- } deriving (Show )
- instance FromJSON Auc where
- parseJSON (Object o ) = Auc <$>
- o .: "auc" <*>
- o .: "item" <*>
- o .: "owner" <*>
- o .: "bid" <*>
- o .: "buyout" <*>
- o .: "quantity" <*>
- o .: "timeLeft" <*>
- o .: "rand" <*>
- o .: "seed"
- parseJSON _ = mzero
- main = do
- au<- C.readFile "a.json"
- let x = decode au :: Maybe AuctionInfo
- case x of
- Just a -> do
- {-putStrLn.show $ a-}
- putStrLn .show.length.auctions.alliance $ a
- putStrLn "ok"
- Nothing -> putStrLn "fail"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement