1

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)

exception

{"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)

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

I'm still getting the same exception, I think I need to add JsonObjectAttribute to the type
Ended up trying a different way and it worked. Dim act As lobbActivity = js.Deserialize(Of lobbActivity)(activityArr)
2

Your properties are not arrays they are strings. Use the following modified class

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.