我正在尝试使用 JavascriptSerializer 在 .NET 中反序列化一些 JSON。我正在使用的 JSON 示例如下:
[{
"dep_date": "2012-07-12",
"tax": 141.53,
"currency": "GBP",
"vcr": "LX",
"dst_apt": "PRG",
"flight_in": [
[
{
"depApt": "PRG",
"dstApt": "FRA",
"depTime": "2012-07-15 19:05:00",
"vcr": "LH",
"carrier": "LH",
"arrTime": "2012-07-15 20:15:00",
"ocr": "LH",
"flightNo": "1401"
},
{
"depApt": "FRA",
"dstApt": "LHR",
"depTime": "2012-07-15 21:30:00",
"vcr": "LH",
"carrier": "LH",
"arrTime": "2012-07-15 22:10:00",
"ocr": "LH",
"flightNo": "922"
}
]
],
"price": 114.0,
"dst_city": "PRG",
"dep_apt": "LCY",
"flight_out": [
[
{
"depApt": "LCY",
"dstApt": "ZRH",
"depTime": "2012-07-12 08:25:00",
"vcr": "LX",
"carrier": "LX",
"arrTime": "2012-07-12 11:15:00",
"ocr": "LX",
"flightNo": "451"
},
{
"depApt": "ZRH",
"dstApt": "PRG",
"depTime": "2012-07-12 12:35:00",
"vcr": "LX",
"carrier": "LX",
"arrTime": "2012-07-12 13:55:00",
"ocr": "2L",
"flightNo": "1486"
}
]
],
"ret_date": "2012-07-15",
}]
我正在使用的实际代码/类是:
<Serializable()> _
Public Class FareResult
Public Property dep_date As String
Public Property tax As String
Public Property currency As String
Public Property vcr As String
Public Property dst_apt As String
Public Property flight_in As List(Of FlightResult)
Public Property price As String
Public Property dst_city As String
Public Property dep_apt As String
Public Property flight_out As List(Of FlightResult)
Public Property ret_date As String
End Class
<Serializable()> _
Public Class FlightResult
Public Property depApt As String
Public Property dstApt As String
Public Property depTime As String
Public Property vcr As String
Public Property carrier As String
Public Property arrTime As String
Public Property ocr As String
Public Property flightNo As String
End Class
Dim jss As New JavaScriptSerializer
Dim oFareResults As Generic.List(Of FareResult) = jss.Deserialize(Of List(Of FareResult))(sJSON)
但是,这只是给我一条消息,说不支持类型 FlightResults 用于数组的反序列化。我尝试创建一个继承 FlightResults 列表的类,我尝试将其设置为数组而不是列表,但它们都给出了相同的异常。
我在这里错过了什么吗?