我正在尝试使用JSON脚本并出现错误;
我设法在行中使用单个数组反序列化JSON,但是此脚本在行中具有多个数组。
我的代码;
Dim s As String = File.ReadAllText("C:\Users\sajid\source\repos\JSON_TO_DATABASE\dummy.json") 'reader.ReadToEnd '
Dim myJs = JsonConvert.DeserializeObject(Of Rootobject)(s)
https://i.ibb.co/7XRyhzk/Error.png(错误消息)
我需要在JSON下面进行反序列化,以便可以在应用程序中使用数据,然后将其保存到数据库中
JSON脚本在这里;
{"SuccessResponse": {
"Head": {
"RequestId": "0b1192a115701283055003672e6b47",
"RequestAction": "GetOrder",
"ResponseType": "Order",
"Timestamp": "2019-10-03T23:45:05+05:00"
},
"Body": {
"Orders": [
{
"OrderId": 103726686259125,
"CustomerFirstName": "ABC",
"CustomerLastName": "",
"OrderNumber": 103125,
"PaymentMethod": "COD",
"Remarks": "",
"DeliveryInfo": "",
"Price": "800.00",
"GiftOption": false,
"GiftMessage": "",
"VoucherCode": "",
"CreatedAt": "2019-05-24 11:30:45",
"UpdatedAt": "2019-06-10 17:25:51",
"AddressBilling": {
"FirstName": "CBD",
"LastName": "",
"Phone": "92HJHJ2",
"Phone2": "",
"Address1": "Pakistan",
"Address2": "",
"Address3": "Punjab",
"Address4": "Lahore",
"Address5": "H",
"CustomerEmail": "",
"City": "Lahore",
"PostCode": "",
"Country": "Pakistan",
"TreeAddressId": ""
},
"AddressShipping": {
"FirstName": "BCD",
"LastName": "",
"Phone": "923UJII102",
"Phone2": "",
"Address1": "Pakistan",
"Address2": "",
"Address3": "Punjab",
"Address4": "Lahore",
"Address5": "H",
"CustomerEmail": "",
"City": "Lahore",
"PostCode": "",
"Country": "Pakistan",
"TreeAddressId": ""
},
"NationalRegistrationNumber": "",
"ItemsCount": 4,
"PromisedShippingTimes": "",
"ExtraAttributes": "",
"Statuses": [
"failed"
],
"Voucher": 75.00,
"ShippingFee": 99.00,
"TaxCode": "",
"BranchNumber": ""
}
]
}
}}
我的班级模型
Public Class Rootobject
Public Property SuccessResponse As Successresponse
End Class
Public Class Successresponse
Public Property Head As Head
Public Property Body As Body
End Class
Public Class Head
Public Property RequestId As String
Public Property RequestAction As String
Public Property ResponseType As String
Public Property Timestamp As Date
Public Property TotalCount As Integer
End Class
Public Class Body
Public Property Orders() As List(Of Order)
Public Property Addressbillings() As List(Of Addressbilling)
Public Property Addressshippings() As List(Of Addressshipping)
End Class
Public Class Order
Public Property OrderId As Long
Public Property CustomerFirstName As String
Public Property CustomerLastName As String
Public Property OrderNumber As Long
Public Property PaymentMethod As String
Public Property Remarks As String
Public Property DeliveryInfo As String
Public Property Price As String
Public Property GiftOption As Boolean
Public Property GiftMessage As String
Public Property VoucherCode As String
Public Property CreatedAt As String
Public Property UpdatedAt As String
Public Property AddressBilling As Addressbilling
Public Property AddressShipping As Addressshipping
Public Property NationalRegistrationNumber As String
Public Property ItemsCount As Integer
Public Property PromisedShippingTimes As String
Public Property ExtraAttributes As String
Public Property Statuses() As String
Public Property Voucher As Single
Public Property ShippingFee As Single
Public Property TaxCode As String
Public Property BranchNumber As String
End Class
Public Class Addressbilling
Public Property FirstName As String
Public Property LastName As String
Public Property Phone As String
Public Property Phone2 As String
Public Property Address1 As String
Public Property Address2 As String
Public Property Address3 As String
Public Property Address4 As String
Public Property Address5 As String
Public Property CustomerEmail As String
Public Property City As String
Public Property PostCode As String
Public Property Country As String
Public Property TreeAddressId As String
End Class
Public Class Addressshipping
Public Property FirstName As String
Public Property LastName As String
Public Property Phone As String
Public Property Phone2 As String
Public Property Address1 As String
Public Property Address2 As String
Public Property Address3 As String
Public Property Address4 As String
Public Property Address5 As String
Public Property CustomerEmail As String
Public Property City As String
Public Property PostCode As String
Public Property Country As String
Public Property TreeAddressId As String
End Class
答案 0 :(得分:1)
我不是100%的人,但初步的印象是我注意到您的班级并未将骆驼装在某些东西上
Public Class Addressshipping
Public Class Addressbilling
装有json的情况下
"AddressShipping"
"AddressBilling"
SuccessResponse
我将浏览这两个文件,以确保它们都相同。
例如,您的SuccessResponse:
Public Property SuccessResponse As Successresponse
与
Public Property Addressbillings() As List(Of Addressbilling)
Public Property Addressshippings() As List(Of Addressshipping)