我正在尝试使用recreations.gov API来查找可用的露营地。当我收到数据时,我不知道如何序列化它。有人能帮我创建正确的类结构吗?我删除了一些可用性和数量条目。每月的每一天都返回一个。
谢了,耶利米
{
"campsites": {
"1": {
"availabilities": {
"2023-08-01T00:00:00Z": "Reserved",
"2023-08-0T00:00:00Z": "Reserved"
},
"campsite_id": "1",
"campsite_reserve_type": "Site-Specific",
"campsite_rules": null,
"campsite_type": "RV NONELECTRIC",
"capacity_rating": "Single",
"loop": "C ",
"max_num_people": 6,
"min_num_people": 0,
"quantities": {
"2023-08-01T00:00:00Z": 0,
"2023-08-31T00:00:00Z": 0
},
"site": "065",
"supplemental_camping": null,
"type_of_use": "Overnight"
},
"2": {
"availabilities": {
"2023-08-01T00:00:00Z": "Reserved",
"2023-08-31T00:00:00Z": "Reserved"
},
"campsite_id": "2",
"campsite_reserve_type": "Site-Specific",
"campsite_rules": null,
"campsite_type": "RV NONELECTRIC",
"capacity_rating": "Single",
"loop": "C",
"max_num_people": 6,
"min_num_people": 0,
"quantities": {
"2023-08-01T00:00:00Z": 0,
"2023-08-31T00:00:00Z": 0
},
"site": "066",
"supplemental_camping": null,
"type_of_use": "Overnight"
}
},
"count": 99
}
我读了大量关于json序列化的文章,并尝试用https://jsonutils.com/创建类,但值变成了类的属性,这毫无意义。我想知道他们返回的JSON是否无效。
Public Class Rootobject
Public Property campsites As Campsites
Public Property count As Integer
End Class
Public Class Campsites
Public Property _1 As _1
Public Property _2 As _2
End Class
Public Class _1
Public Property availabilities As Availabilities
Public Property campsite_id As String
Public Property campsite_reserve_type As String
Public Property campsite_rules As Object
Public Property campsite_type As String
Public Property capacity_rating As String
Public Property _loop As String
Public Property max_num_people As Integer
Public Property min_num_people As Integer
Public Property quantities As Quantities
Public Property site As String
Public Property supplemental_camping As Object
Public Property type_of_use As String
End Class
Public Class Availabilities
Public Property _20230801T000000Z As String
Public Property _2023080T000000Z As String
End Class
Public Class Quantities
Public Property _20230801T000000Z As Integer
Public Property _20230831T000000Z As Integer
End Class
Public Class _2
Public Property availabilities As Availabilities1
Public Property campsite_id As String
Public Property campsite_reserve_type As String
Public Property campsite_rules As Object
Public Property campsite_type As String
Public Property capacity_rating As String
Public Property _loop As String
Public Property max_num_people As Integer
Public Property min_num_people As Integer
Public Property quantities As Quantities1
Public Property site As String
Public Property supplemental_camping As Object
Public Property type_of_use As String
End Class
Public Class Availabilities1
Public Property _20230801T000000Z As String
Public Property _20230831T000000Z As String
End Class
Public Class Quantities1
Public Property _20230801T000000Z As Integer
Public Property _20230831T000000Z As Integer
End Class
1条答案
按热度按时间yhived7q1#
这个解决方案只需要一点手工操作就可以实现。
JSON类:
一个解析传入json的方法,并给你留下一个露营地的集合: