无法反序列化JSON文件
我试图使用JSON脚本并得到错误 我已经成功地用一行中的单个数组反序列化了JSON,但是这个脚本在一行中有多个数组 我的代码无法反序列化JSON文件,json,database,vb.net,Json,Database,Vb.net,我试图使用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) 错误按摩 我需要下面这个J
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)
错误按摩
我需要下面这个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
我不是百分之百的,但是我注意到你的课并不是在做某些事情
Public Class Addressshipping
Public Class Addressbilling
json是驼峰式的
"AddressShipping"
"AddressBilling"
SuccessResponse
我会检查这两个文件,以确保它们都是相同的。
例如,您的SuccessResponse:
公共属性SuccessResponse作为SuccessResponse
vs
公共财产地址账单作为地址账单列表
公共属性Addressshipping作为Addressshipping的列表
您需要发布用于反序列化JSON的模型的类结构。这里的根对象未定义。@Jimi我已经发布了我的类Model@Jimi我知道这是JSON脚本状态中的问题:[失败],但这是我通过webAPI得到的,我不想手动修改它将公共属性状态更改为String,将公共属性状态更改为ListOf String。在公共类主体中,虽然不是严格必要的,但删除父类,例如,将公共财产订单作为ListOf订单删除到将公共财产订单作为ListOf订单Order@Jimi你太棒了。。。谢谢您的支持。@Jimi我知道这是JSON脚本状态中的问题:[失败],但这是我通过webAPI得到的,我不想修改它manully@Jimi-如果我要将其从状态:[失败]修改为状态:失败,则其他一切都可以,一切都很好,但由于这是webAPI,我不想手动修改它,