我有一个要转换为vb.net对象的json,我尝试为其创建类,但没有成功。 JSON响应如下所示:
{
"status": "success",
"result": {
"0": {
"id": 4991,
"sender_id": 2971,
"due_date": "0000-00-00 00:00:00",
"language_id": "sv",
"last_event": "2017-05-17 09:58:38",
"visible_name": "new offer",
"name": "new offer",
"reminder_date": "0000-00-00",
"offer_status": 0,
"offer_type": 1,
"user_details": "{\"first_name\":\"Beta\",\"last_name\":\"\",\"company\":\"Simplesign\",\"email\":\"beta@yopmail.com\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"00923453596885\",\"post_code\":\"\",\"city\":\"\"}",
"unique_id": "591c02ae8c442",
"created_date": "2017-05-17 09:58:38",
"signed_date": "0000-00-00 00:00:00",
"last_sent_emailreminder": "0000-00-00 00:00:00",
"last_sent_smsreminder": "0000-00-00 00:00:00",
"unread_notification": 0,
"offer_rejected": 0,
"recieved_by": 0,
"pdf_url": "https://esign.simplesign.io/avtal/downloadpdf/4991/5b8648da173a5",
"details": [
{
"id": 5668,
"offer_sent_id": 4991,
"customer_id": 1556,
"offer_status": 1,
"sent_date": "2017-05-17 09:59:15",
"email_read_date": "0000-00-00 00:00:00",
"document_read_date": "0000-00-00 00:00:00",
"signed_date": "0000-00-00 00:00:00",
"reject_date": "0000-00-00 00:00:00",
"sender_ip": "103.75.244.108",
"read_ip": "",
"signed_ip": "",
"gps_location": "",
"first_name": "John",
"last_name": "Doe",
"company": "",
"is_sender": 0,
"extra_fields": "",
"user_details": "{\"id\":1556,\"full_name\":\"John\",\"email\":\"johndoe@yopmail.com\",\"company\":\"\",\"reg_no\":\"\",\"mobile\":\"\",\"address\":\"\",\"city\":\"\",\"zipcode\":\"\",\"country\":\"\",\"extra_fields\":\"\",\"invitation_order\":1,\"confirmation\":1,\"role\":1,\"id_attachment\":0,\"authentication\":1,\"paypal_amount\":0,\"invitation_type\":1}",
"request_attachment": "[]",
"pin_code": 0,
"invitation_order": 1,
"email": "johndoe@yopmail.com",
"unique_id": "591c02d30379f",
"signature": "",
"signature_type": "",
"signature_font": "",
"authentication_method": 1,
"role": 1,
"id_attachments": 0,
"paypal_amount": 0,
"offer_confirmation": 1,
"invitation_type": 1,
"attached_id": "",
"signature_image": "",
"recieved_by": 0,
"req_attached": "",
"is_pending": 0,
"schedule": "",
"schedule_userid": "",
"isretargeting": 1,
"signature_contrast": "",
"device_details": "",
"evidence_data": "",
"bankid_data": ""
}
],
"senderDetails": [
{
"id": 5667,
"offer_sent_id": 4991,
"customer_id": 0,
"offer_status": 4,
"sent_date": "2017-05-17 09:59:15",
"email_read_date": "0000-00-00 00:00:00",
"document_read_date": "0000-00-00 00:00:00",
"signed_date": "2017-05-17 09:59:15",
"reject_date": "0000-00-00 00:00:00",
"sender_ip": "103.75.244.108",
"read_ip": "",
"signed_ip": "103.75.244.108",
"gps_location": "",
"first_name": "Beta",
"last_name": "",
"company": "Simplesign",
"is_sender": 1,
"extra_fields": "",
"user_details": "{\"id\":2971,\"full_name\":\"Beta\",\"company\":\"Simplesign\",\"address\":\"\",\"country\":\"\",\"zipcode\":\"\",\"city\":\"\",\"reg_no\":\"\",\"email\":\"beta@yopmail.com\"}",
"request_attachment": "",
"pin_code": 0,
"invitation_order": 1,
"email": "beta@yopmail.com",
"unique_id": "591c02d3018d0",
"signature": "",
"signature_type": "",
"signature_font": "",
"authentication_method": 0,
"role": 0,
"id_attachments": 0,
"paypal_amount": 0,
"offer_confirmation": 0,
"invitation_type": 0,
"attached_id": "",
"signature_image": "",
"recieved_by": 0,
"req_attached": "",
"is_pending": 0,
"schedule": "",
"schedule_userid": "",
"isretargeting": 1,
"signature_contrast": "",
"device_details": "",
"evidence_data": "",
"bankid_data": ""
}
]
},
"userSetting": {
"userMsg": "",
"userSMS": "",
"userSubject": ""
},
"pagination": {
"totalRecords": 1,
"pagelimit": 10,
"currentpage": 0
}
},
"totaldata": {
"sent": 1,
"reviewed": 0,
"signed": 0,
"rejected": 0
}
}
现在的表示形式如下:
Imports Microsoft.VisualBasic
Imports Newtonsoft.Json
Public Class RecipientDetail
<JsonProperty("id")>
Public Property id As Integer
<JsonProperty("customer_id")>
Public Property customer_id As Integer
<JsonProperty("sent_date")>
Public Property sent_date As String
<JsonProperty("document_read_date")>
Public Property document_read_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("first_name")>
Public Property first_name As String
<JsonProperty("company")>
Public Property company As String
<JsonProperty("is_sender")>
Public Property is_sender As String
<JsonProperty("extra_fields")>
Public Property extra_fields As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("invitation_order")>
Public Property invitation_order As Integer
<JsonProperty("email")>
Public Property email As String
<JsonProperty("offer_confirmation")>
Public Property offer_confirmation As String
<JsonProperty("invitation_type")>
Public Property invitation_type As String
End Class
Public Class SenderDetail
<JsonProperty("id")>
Public Property id As Integer
<JsonProperty("customer_id")>
Public Property customer_id As Integer
<JsonProperty("sent_date")>
Public Property sent_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("first_name")>
Public Property first_name As String
<JsonProperty("company")>
Public Property company As String
<JsonProperty("is_sender")>
Public Property is_sender As String
<JsonProperty("extra_fields")>
Public Property extra_fields As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("email")>
Public Property email As String
End Class
Public Class ContractDetail
<JsonProperty("sender_id")>
Public Property sender_id As Integer
<JsonProperty("last_event")>
Public Property last_event As String
<JsonProperty("visible_name")>
Public Property visible_name As String
<JsonProperty("offer_status")>
Public Property offer_status As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("created_date")>
Public Property created_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("offer_rejected")>
Public Property offer_rejected As String
<JsonProperty("name")>
Public Property name As String
<JsonProperty("contract_id")>
Public Property contract_id As Integer
<JsonProperty("recipientDetails")>
Public Property recipientDetails As IList(Of RecipientDetail)
<JsonProperty("pdf_url")>
Public Property pdf_url As String
<JsonProperty("senderDetails")>
Public Property senderDetails As IList(Of SenderDetail)
End Class
Public Class Pagination
<JsonProperty("totalRecords")>
Public Property totalRecords As Integer
<JsonProperty("pagelimit")>
Public Property pagelimit As Integer
<JsonProperty("currentpage")>
Public Property currentpage As Integer
End Class
Public Class Result
Public Property ContractDetail As IList(Of ContractDetail)
End Class
Public Class SS_History
<JsonProperty("status")>
Public Property status As String
<JsonProperty("result")>
Public Property result As Result
End Class
问题在于结果为空,因此出于某种原因,看来我把结果类做错了。
如果有人对解决方法有任何建议,我将不胜感激。
彼得
答案 0 :(得分:0)
首先,复制json字符串。
打开VS,添加一个新的空类。
在“ VS”菜单上选择“编辑”,然后将“选择性粘贴”和“粘贴Json”作为类。类将自动生成。
第一个对象将是RootObject,在该对象上添加Newtonsoft的装饰器。 添加所有装饰器后,您还可以更改属性名称或对象名称。
Imports Newtonsoft.Json
公共类Rootobject
<JsonProperty("status")>
Public Property status As String
<JsonProperty("result")>
Public Property result As Result
<JsonProperty("totaldata")>
Public Property totaldata As Totaldata
结束类 等等.. 以这种方式反序列化: Json