Hi.
I have error while generation Json. Error is Value of type 'ValueAddedService' cannot be converted to System.Collections.Generic.List(Of ValueAddedService)'
Also date and time is "messageDateTime ="\/Date(1674459281468)\/" is not date time format like "2023-01-19T11:20:27+08:00"
pls advice me regarding above both issue
Thank you
Maideen
What I have tried:
Dim root As List(Of Root) = New List(Of Root)()
Dim PickupAddress As PickupAddress = New PickupAddress With {
.name = "xxy Company LTD",
.address1 = "1, 11,13, Jalan Rajawali",
.address2 = "Bandar Puchong Jaya",
.city = "Puchong",
.country = "MY",
.district = "Puchong",
.state = "Selangor",
.postCode ="47000",
.email = "sales@xxy.com",
.phone = "069076 1651"
}
Dim shipperAddress As ShipperAddress = New ShipperAddress With {
.name = "xxy Company LTD",
.address1 = "1, 11,13, Jalan Rajawali",
.address2 = "Bandar Puchong Jaya",
.city = "Puchong",
.country = "MY",
.district = "Puchong",
.state = "Selangor",
.postCode ="47000",
.email = "sales@xxy.com",
.phone = "069076 1651"
}
Dim consignement As ConsigneeAddress = New ConsigneeAddress With {
.name = "Poliklinik Gunwant",
.address1 = "Lot 9797, Jalan Menteri",
.address2 = "Sungai Besar Selangor",
.city = "Sungai Besar",
.state = "Selangor",
.district = "Sungai Besar",
.country = "MY",
.postCode = "46000",
.email = "",
.phone = "092548 3257"
}
Dim valADDService As ValueAddedService = New ValueAddedService With {
.vasCode = "PPOD"}
Dim valueAddedServices As List(Of ValueAddedServices) = New List(Of ValueAddedServices)()
valueAddedServices.Add(New ValueAddedServices With {.valueAddedService = valADDService})
Dim shipmentPieces As List(Of ShipmentPiece) = New List(Of ShipmentPiece)()
shipmentPieces.Add(New ShipmentPiece With {
.pieceID = "1"})
Dim shipItem As List(Of ShipmentItem) = New List(Of ShipmentItem)()
shipItem.Add(New ShipmentItem With {
.consigneeAddress = consignement,
.shipmentID = "123456789",
.packageDesc = "abc",
.totalWeight = "1",
.totalWeightUOM = "KG",
.dimensionUOM = "CM",
.productCode = "PDO",
.currency = "USD",
.remarks = "",
.isMult = "true",
.deliveryOption = "C",
.shipmentPieces = shipmentPieces
})
Dim hdr As Hdr = New Hdr With {
.accessToken ="123456789",
.messageDateTime ="\/Date(1674459281468)\/",
.messageLanguage = "en",
.messageType = "SHIPMENT",
.messageVersion = "1.4"
}
Dim bd As Bd = New Bd With {
.pickupAccountId = "123587",
.soldToAccountId = "325784",
.pickupDateTime = "\/Date(1674459281468)\/",
.handoverMethod = "1",
.pickupAddress = PickupAddress,
.shipperAddress = shipperAddress,
.shipmentItems = shipItem
}
Dim manifesto As ManifestRequest = New ManifestRequest With {
.bd = bd,
.hdr = hdr
}
root.Add(New Root With {
.manifestRequest = manifesto
})
Dim serializer As JavaScriptSerializer = New JavaScriptSerializer()
v_jsonData = ""
v_jsonData = serializer.Serialize(root)
Me.txtJsonData.Text = serializer.Serialize(root)
Result should be below.
{
"manifestRequest": {
"hdr": {
"messageType": "SHIPMENT",
"messageDateTime": "2023-01-19T11:20:27+08:00",
"accessToken": "f0108fb771fa4d269e10d8702f487b93",
"messageVersion": "1.4",
"messageLanguage": "en"
},
"bd": {
"pickupAccountId": "5264574522",
"soldToAccountId": "5264574522",
"pickupDateTime": "2023-01-19T11:20:27+08:00",
"handoverMethod": 1,
"pickupAddress": {
"name": "Jet Pharam",
"address1": "adddress1",
"address2": "address2 .",
"city": "puchong",
"state": "selangor",
"district": "puchong",
"country": "MY",
"postCode": "46000",
"phone": "123456789",
"email": "abc@jetpharma.com"
},
"shipperAddress": {
"name": "Jet Pharam",
"address1": "Address1",
"address2": "Address2",
"city": "Puchong",
"state": "Selangor",
"district": "Puchong",
"country": "MY",
"postCode": "46000",
"phone": "123456789",
"email": "abc@jetpharma.com"
},
"shipmentItems": [
{
"consigneeAddress": {
"name": "Poliklinik Gunwant",
"address1": "Lot 9797, Jalan Menteri",
"address2": "Lot 9797, Jalan Menteri",
"city": "Sungai Besar",
"state": "Selangor",
"district": "Sungai Besar",
"country": "MY",
"postCode": "45300",
"phone": "123456789",
"email": "abc@xxx.com"
},
"shipmentID": "MYJMS346524660",
"packageDesc": "asdasad",
"totalWeight": 1,
"totalWeightUOM": "G",
"dimensionUOM": "CM",
"productCode": "PDO",
"currency": "MYR",
"remarks": "JETPharma",
"isMult": "true",
"valueAddedServices": {
"valueAddedService": [
{
"vasCode": "PPOD"
}
]
},
"deliveryOption": "C",
"shipmentPieces": [
{
"pieceID": 11
}
]
}
]
}
}
}