我是Haskell和Yesod开发的新手。 我尝试使用Aeson从Google Web Api解析JSON。 我的JSON就像
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 47.2487941,
"lng" : 39.7119239
},
"viewport" : {
"northeast" : {
"lat" : 47.2488398,
"lng" : 39.71313905
},
"southwest" : {
"lat" : 47.24865699999999,
"lng" : 39.71151884999999
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
"id" : "5aae9c47cad3016c64d3cc2c8d438ae656c8c0af",
"name" : "AMAKS Congress hotel",
"photos" : [
{
"height" : 2304,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/116238492021115373516/photos\"\u003eDmitry Semenov\u003c/a\u003e"
],
"photo_reference" : "CoQBdwAAAP5F6Xu0nGvQ8wjAyY4ENNKEWzw8CohQU_2Z15oXWIQOvzwAOBQduK4OQfh-nRyw0iKCwLMS2o9fKanMcxpC4xop22SrxZI45OZWmvC-bTf80kJlgdnlU0q-AsncUxcP6sbfWMaTmAPCsqiAFLJhHwHD93VXCvyV2V4pC2CUpWKAEhBAr9aS0xoapQvNmvcUYfU7GhT3IKDXEdZ49LtEeMXMaBQKlNZ6DQ",
"width" : 4096
}
],
"place_id" : "ChIJNT2qOT7r40ARrxvwbj2Huxg",
"rating" : 4.1,
"reference" : "CmRRAAAAUR4QujRBtpkltqU51qCjuihX1JDEgX9ijFzkTeWGWkeQkw4spvaKqCPUrYit4jNs5AyT1hV-y0M72U2CtOTYgT_6chw5KAq0sB3l1k18BOoioDJqTL6HQ_kvqNn62ISIEhA-lNI9YXDt-cjErgJqHjGFGhQpYucBzRg9yilMU0MEn6b293lVUQ",
"scope" : "GOOGLE",
"types" : [
"bowling_alley",
"bakery",
"lodging",
"restaurant",
"food",
"store",
"point_of_interest",
"establishment"
],
"vicinity" : "проспект Михаила Нагибина, 19, Ростов-на-Дону"
},
/ more items here
"status" : "ok"
}
我创建了用于表示JSON的数据:
data Restaurant = Restaurant {status :: Text} deriving (Show, Generic)
它有效,我可以提取状态。但是当谈到更复杂的封闭字段时,例如"结果",我不知道如何描述和使用它。 那我该怎么写而不是???在
data Restaurant = Restaurant {results :: ???, status :: Text} deriving (Show, Generic)
然后我如何才能访问内部的项目(名称,评级等)? 谢谢!