将json数组反序列化为vb .NET对象异常-由于类型需要数组,因此无法序列化为 [英] Deserialize json array to vb .NET object exception - Cannot serialize into because type requires array

查看:114
本文介绍了将json数组反序列化为vb .NET对象异常-由于类型需要数组,因此无法序列化为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循反序列化数组的准则,但无法弄清楚为什么总是收到此异常.我还尝试了一个非空的json字符串,与下面的字符串不同.

I am following the guidelines for deserializing my array but can't figure out why I keep getting this exception. I have also tried this with a non-empty json string unlike the one below.

Private Class lobbActivity
    Public Property billNum_List() As String
    Public Property ruleOrReg_List() As String
    Public Property ratemaking_List() As String
    Public Property PcontrNum_List() As String
    Public Property Ptitle_List() As String
    Public Property MuniOrd_List() As String
    Public Property MuniRed_List() As String
    Public Property ExOrders_List() As String
    Public Property TribeSub_List() As String
    Public Property Tribes_List() As String
End Class

Function JSONCreateLobbyist(ByVal activityArr As String)
     Dim item = Newtonsoft.Json.JsonConvert.DeserializeObject(Of lobbActivity())(activityArr)

例外

{"billNum_List":["aa","aa"],"ruleOrReg_List":["vbb","vbb"],"ratemaking_List":["bb","bb"],"PcontrNum_List":[],"Ptitle_List":[],"MuniOrd_List":[],"MuniRed_List":[],"ExOrders_List":[],"TribeSub_List":[],"Tribes_List":[]}

最终使用了有效的不同语法

Ended up using different syntax that worked

Dim act As lobbActivity = js.Deserialize(Of lobbActivity)(activityArr)

推荐答案

如果您在Visual Studio中使用粘贴为JSON"功能,则不能正确定义数组属性.

If you are using the Paste as JSON feature in Visual Studio, it does not define array properties correctly.

Private Class lobbActivity
    Public Property billNum_List As String()
    Public Property ruleOrReg_List As String()
    Public Property ratemaking_List As String()
    Public Property PcontrNum_List As String()
    Public Property Ptitle_List As String()
    Public Property MuniOrd_List As String()
    Public Property MuniRed_List As String()
    Public Property ExOrders_List As String()
    Public Property TribeSub_List As String()
    Public Property Tribes_List As String()
End Class

这篇关于将json数组反序列化为vb .NET对象异常-由于类型需要数组,因此无法序列化为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆