0

I am trying to serialise some JSON from nested objects into a string. However I am having issues with the arrays within the objects

Class RequestTaxes
    Public Property usrname As String
    Public Property pswrd As String
    Public Property isAudit As Boolean
    Public Property currn As String
    Public Property lines() As TaxLines
End Class


Class TaxLines
    Public Property debCredIndr As Integer
    Public Property goodSrvCd As String
    Public Property grossAmt As Double
    Public Property lnItmId As String
    Public Property qnty As Double
    Public Property trnTp As Integer
    Public Property accntDt As DateTime
    Public Property custVendName As String
    Public Property custVendCd As String
    Public Property orgCd As String
End Class

However when I try to pass the serialised string to the API It is refused because the square brackets around the "lines" list are missing.

Does anyone know who to put these in when using Newtonsoft?

 Dim Settings As New JsonSerializerSettings
 Settings.NullValueHandling = NullValueHandling.Ignore
 Dim InputString As String = JsonConvert.SerializeObject(message, Settings)

"message" contains a populated object of type RequestTaxes

3
  • What is the exact error message? I dont think it really has to do with brackets Commented Sep 4, 2017 at 14:09
  • 1
    This may be a duplicate of Cannot Json deserialize Youtube data with VB.net, but we need to see the JSON and the full ToString() output of the exception including the message, traceback, exception type and inner exception to be sure. Commented Sep 4, 2017 at 16:51
  • 1
    Looking at that question, it's closely relatied from what we can see, but arguably not a dupe since this is serialising vs deserialising. Nice find though. Commented Sep 5, 2017 at 7:41

2 Answers 2

1

I think you have your property declarations a bit off.

Public Property lines() As TaxLines

is equivalent to

Public Property lines As TaxLines

meaning that your TaxLines is only a single instance, not an array.

You need to add parantheses at the end of the line like so:

Public Property lines() As TaxLines()

Sign up to request clarification or add additional context in comments.

Comments

0

I actually needed to do

Public Property lines As List(of TaxLines)

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.