这个问题与我之前提出的另一个问题有关。
我正在从 JSON 文件中读取数据并尝试将它们解析为我制作的数据类型。
{
"rooms":
[
{
"id": "room1",
"description": "This is Room 1. There is an exit to the north.\nYou should drop the white hat here.",
"items": ["black hat"],
"points": 10,
"exits": [
{
"direction": "north",
"room": "room2"
}
],
"treasure": ["white hat"]
},
{
"id": "room2",
"description": "This is Room 2. There is an exit to the south.\nYou should drop the black hat here.",
"items": [],
"points": 10,
"exits": [
{
"direction": "south",
"room": "room1"
}
],
"treasure": ["black hat"]
}
]
}
我的房间用户定义类型是:
type room = {
room_id : int ;
room_description : string ;
room_items : item list ;
room_points : int ;
room_exits : exit list ;
room_treasure : item list ;
}
and exit = direction * room
但是,房间有一个“退出”字段,它本身就是一个“房间”类型。然后当我尝试为room1创建记录时,我首先需要定义room2,但是为了定义room2,我需要知道 room1。这似乎是一种循环类型。
谁能帮我这个?