I need to create a JSON that will look as below.
{
"ShipmentId": "111888",
"BizId": "MORRIS",
"BizSalesOrder": null,
"Status": "00",
"OrderType": "S01",
"OrderClass": "PACKSHIP",
"ShipmentLines": [
{
"ShipmentId": "111888",
"QtyOrdered": 30.00,
"QtyRequired": 30.00,
"QtyDueOut": 0.00,
"SOLineId": 1.00,
"Stage": "90"
},
{
"ShipmentId": "111888",
"QtyOrdered": 40.00,
"QtyRequired": 40.00,
"QtyDueOut": 0.00,
"SOLineId": 2.00,
"Stage": "90"
},
{
"ShipmentId": "111888",
"QtyOrdered": 10.00,
"QtyRequired": 10.00,
"QtyDueOut": 0.00,
"SOLineId": 3.00,
"Stage": "90"
},
{
"ShipmentId": "111888",
"QtyOrdered": 5.00,
"QtyRequired": 5.00,
"QtyDueOut": 0.00,
"SOLineId": 4.00,
"Stage": "90"
}
],
"ShipAddress": [
{
"Table": "SHH",
"ShipmentId": "111888",
"AddressId": "ADD1",
"Name": "John Smith",
"Line1": "20 Michelin Ave",
"Line2": null,
"City": "LONDON",
"Postcode": "A99 9BC",
"Country": "GB"
}
],
"ShipContacts": [],
"ShipmentDespatch": []
}
I have classes from http://www.jsonutils.com/ (below) yet I'm pretty sure that ShipmentLines should be a "list(of ShipmentLine)", but that's still quite confusing for me..
Public Class ShipmentLine
Public Property ShipmentId As String
Public Property QtyOrdered As Double
Public Property QtyRequired As Double
Public Property QtyDueOut As Double
Public Property SOLineId As Double
Public Property Stage As String
End Class
Public Class ShipAddress
Public Property Table As String
Public Property ShipmentId As String
Public Property AddressId As String
Public Property Name As String
Public Property Line1 As String
Public Property Line2 As Object
Public Property City As String
Public Property Postcode As String
Public Property Country As String
End Class
Public Class Shipment
Public Property ShipmentId As String
Public Property BizId As String
Public Property BizSalesOrder As Object
Public Property Status As String
Public Property OrderType As String
Public Property OrderClass As String
Public Property ShipmentLines As List(Of ShipmentLine)
Public Property ShipAddress As List(Of ShipAddress)
Public Property ShipContacts As Object()
Public Property ShipmentDespatch As Object()
End Class
I can do 1 level JSON (below), but i have problems with nested (and) multiple objects in 1 nest issue.
I'm new to VB.NET and an amateur in programming(as you can see), so clear instructions would be appreciated.
Shipping Lines are all in Listview1 (left to right from ShipmentId to Stage) so I'm not really sure how to get them and serialize them from Listview1 into a JSON neither.
If you could please write a code for me on how to serialize it what i have got below, but this is only level one of json, no nesting...
Please help, I've been through StackOverflow forum a lot and I'm just repeating all posts now and I can't understand them...
Dim Ship As New Shipment
Ship.ShipmentId = TextBox1.Text
Ship.BizId = TextBox2.Text
Ship.Status = "00"
Ship.OrderType = TextBox3.Text
Ship.Type = TextBox4.Text
Ship.OrderClass = TextBox5.Text
Dim json As String = JsonConvert.SerializeObject(Ship).ToString