まだジェネリックを使用していない場合は、TEXT.JSON のインスタンスを使用する方法を次に示します。
import Text.JSON
data SO = SO {
name :: String,
mytype :: Int,
code :: String,
options :: [Option]
} deriving (Show)
data Option =Option {
atb :: KV
}
data KV = KV {
desc :: String,
v:: Bool
}
instance JSON SO where
showJSON ge = makeObj
[ ("name", showJSON $ name ge),
("type", showJSON $ mytype ge),
("options", showJSON $ options ge)
]
readJSON = error "readJSON not implemented for SO"
instance JSON Option where
showJSON ge = makeObj
[ ("atb", showJSON $ atb ge)
]
readJSON = error "readJSON not implemented for Option"
instance JSON KV where
showJSON ge = makeObj
[ ("description", showJSON $ desc ge),
[ ("value", showJSON $ v ge)
]
readJSON = error "readJSON not implemented for kv"
--encode $ SO .........