Peter Nordberg
asked on
Object error when adding to list
Hi,
I have these classes:
I'm now trying to build this as an object that I can serialize into json like this:
The problem is that I get an error that an object doesn't exist when adding an party item to the lost of parties as can be seen in below image.
What am I doing wrong and how can I fix it?
Peter
I have these classes:
Public Class Party
Public Property partyIdentifier As String
Public Property email As String
Public Property telephone As String
Public Property role As String
End Class
Public Class Car
Public Property registrationNumber As String
Public Property registrationNumberMissing As Boolean
Public Property model As String
Public Property used As Boolean
Public Property year As Integer
Public Property mileage As Integer
Public Property objectGroupType As String
End Class
Public Class Calculation
Public Property cashPrice As Integer
Public Property downPayment As Integer
Public Property residualDebt As Integer
Public Property creditTime As Integer
Public Property interest As Double
End Class
Public Class Insurance
Public Property monthlyCost As Integer
End Class
Public Class Finance
Public Property contractType As String
Public Property customerType As String
Public Property customerLicenceType As String
Public Property Parties As List(Of Party)
Public Property car As Car
Public Property calculation As Calculation
Public Property profileId As Integer
Public Property campaignId As Integer
Public Property plannedDeliveryDate As DateTime
Public Property insurance As Insurance
End Class
I'm now trying to build this as an object that I can serialize into json like this:
If Not Page.IsPostBack Then
Dim f As New Finance
' Basic
f.contractType = "Installment"
f.customerType = "Private"
f.customerLicenceType = "SwedishDriversLicense"
' Parties
Dim p As New Party With {
.partyIdentifier = "8811119307",
.email = "nordberg.peter@gmail.com",
.telephone = "0854545656",
.role = "Buyer"
}
f.Parties.Add(p)
Dim json As String = JsonConvert.SerializeObject(f)
Label1.Text = json
End If
The problem is that I get an error that an object doesn't exist when adding an party item to the lost of parties as can be seen in below image.
What am I doing wrong and how can I fix it?
Peter
Parties is not being initialized. Who created the Finance class? Maybe initialized this collection in the class constructor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Peter
Peter