解码哈斯克尔
问题描述:
一个复杂的字符串我已经做了JSON哈斯克尔解析器这是工作完全正确的解析器解码哈斯克尔
decodeToMaybeValue::BLC.ByteString->Maybe Value
decodeToMaybeValue = decode
main = do
interact (show . decodeToMaybeValue . BLC.pack)
该编译器直接编译时工作绝对正确的,但是当我尝试存储将字符串放入一个变量来解码它会产生这个错误。我试图
x =`"{\"apiVersion\": \"2.0\",\"data\": {\"updated\": \"2010-01-07T19:58:42.949Z\",\"totalItems\": 800,\"startIndex\": 1,\"itemsPerPage\": 1,\"items\": [{\"id\": \"hYB0mn5zh2c\",\"uploaded\":\"2007-06-05T22:07:03.000Z\",\"updated\": \"2010-01-07T13:26:50.000Z\",\"uploader\": \"GoogleDeveloperDay\",\"category\": \"News\",\"title\": \"Google Developers Day US - Maps API Introduction\",\"description\": \"Google Maps API Introduction ...\",\"tags\": [\"GDD07\",\"GDD07US\",\"Maps\"],\"duration\": 2840,\"aspectRatio\": \"widescreen\",\"rating\": 4.63,\"ratingCount\": 68,\"viewCount\": 220101,\"favoriteCount\":201,\"commentCount\": 22 }]}}"`
y = BLC.pack x
Invalid type signature: decode y :: Maybe Value
-- Should be of form <variable> :: <type>
有没有人有想法呢?
答
你将不再需要你的字符串转换,如果你在该文件的第一行使用{-# LANGUAGE OverloadedStrings #-}
为文本....
这是你想要的吗?
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson
import qualified Data.ByteString.Lazy.Char8 as BLC
decodeToMaybeValue::BLC.ByteString->Maybe Value
decodeToMaybeValue = decode
theData="{\"a\": \"b\"}" --Put in the data here.
main = do
print $ decodeToMaybeValue theData
是的,我完全想要这个 – 2014-11-03 21:27:00