簡體   English   中英

從json轉換為vb.net類時對象為空

[英]Object empty on conversion from json to vb.net classes

我有一個要轉換為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

問題是結果為空,因此由於某種原因,看來我做錯了結果類。

如果有人對如何解決提出建議,我將不勝感激。

彼得

首先,復制json字符串。

打開VS,添加一個新的空類。

在“ VS”菜單上選擇“編輯”,然后選擇“選擇性粘貼”和“粘貼Json作為類”。 類將自動生成。

第一個對象將是RootObject,在該對象上添加Newtonsoft的裝飾器。 添加所有裝飾器之后,您還可以更改屬性名稱或對象名稱。

Imports Newtonsoft.Json

公共類根對象

<JsonProperty("status")>
Public Property status As String

<JsonProperty("result")>
Public Property result As Result

<JsonProperty("totaldata")>
Public Property totaldata As Totaldata

結束類等。以這種方式反序列化: Json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM