JSON未取消序列化为自定义类



这是我第一次使用JSON。我已经将一个自定义类序列化为List,但它不会取消序列化。感谢的任何帮助

Dim Appointments As New List(Of UserAppointments)()
Using dt As DataTable = GetUserAppointments(ApptRequest.UserID, ApptRequest.PeriodFrom, ApptRequest.PeriodUntil)
For Each appt As DataRow In dt.Rows
Appointments.Add(New UserAppointments With {.AppointmentID = CType(appt.Item("UniqueID").ToString, Long)})
Next
End Using
Dim JSON As String = js.Serialize(JsonConvert.SerializeObject(Appointments))

它产生

"[{\"AppointmentID":33},{\"AppointmentID\":34},}"Appointment ID":35},"Appointments ID":36},《约会ID》:37},"约会ID":38},约会ID":39},:376},{\"约会ID":377}

当我再次尝试取消对的序列化时

Dim rslt As List(Of UserAppointments) = JsonConvert.DeserializeObject(Of List(Of UserAppointments))(JSON)

我得到以下错误

转换值时出错"[{"约会ID":33},{"预约ID":34},}"约会ID:35},"约会ID":36},‘约会ID’:37},’约会ID":38},'约会ID‘:39},"约会ID‘:40},":687}]"以键入"System.Collections.Generic.List`1[NetworkRequests+UserAppointments]"。路径",第1行,位置331。

我相信你的问题出在这行。您正在将其序列化两次。

将JSON Dim为字符串=js。序列化(JsonConvert.SerializeObject(约会))

你只试过吗

将JSON Dim为字符串=JsonConvert.SerializeObject(约会)

还是有理由将其翻倍?

相关内容

  • 没有找到相关文章

最新更新