Object empty on conversion from json to vb.net classes

Hi,

I have this json that I want to convert to vb.net objects:
{

"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
}
}

Open in new window


The representation looks like this now:
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

    Public Sub New()

    End Sub
End Class

Open in new window


The problem is that the result is empty, so for some reason it seems that I've done the result class wrong.

If someone have a suggestion of how to solve it I would be most grateful.

Peter
Peter NordbergIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPRetiredCommented:
when I used powershell to convert the json I hit a few stumbling blocks

$mydata = (Get-Content -Path ..\..\jsondata.json) -join "`n" | ConvertFrom-Json
 $mydata | Format-List
 $test= $mydata.result.0
 $test.details

Open in new window



status    : success
result    : @{0=; userSetting=; pagination=}
totaldata : @{sent=1; reviewed=0; signed=0; rejected=0}





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":"","add
                        ress":"","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           :
Peter NordbergIT ManagerAuthor Commented:
Hi and thanks for answer,

How can I use that result to adjust my code?

Peter
David Johnson, CD, MVPRetiredCommented:
As you can see some objects return objects. Concentrate on the objects that you are interested in. You might want to convert the json to xml if you are more familiar with xml
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

it_saigeDeveloperCommented:
Just looking at the JSON, it appears to be a little malformed and inconsistent.  For example;
'result':{
	// starts out as a dictionary
	'0':{},
	// but then introduces a pair of additional objects
	'userSetting':{},
	'pagination':{}
},

Open in new window

Contains two representation of the same property with different types:
// In the details array
'request_attachment':[]
// In the senderDetails array
'request_attachment':''

Open in new window

Invalid convertable values:
'due_date':'0000-00-00 00:00:00'
'reminder_date':'0000-00-00'

Open in new window

Anyhow, making some assumptions, here is a starting point in VB.NET:
Imports System.Net
Imports Newtonsoft.Json

Module Module1
    Dim data = "{
        '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
        }
    }"

    Sub Main()
        Dim converted = JsonConvert.DeserializeObject(Of ResponseMessage)(data)
        Console.WriteLine()
    End Sub
End Module

Class ResponseMessage
    Public Property Status() As String
    Public Property Result() As MessageResult
    Public Property TotalData() As DataStatistics
End Class

Class MessageResult
    'Inherits Dictionary(Of Integer, MessageDetail)
    <JsonProperty("0")>
    Public Property MessageDetail() As MessageDetail
    Public Property UserSetting() As UserSetting
    Public Property Pagination() As Pagination
End Class

Class MessageDetail
    Public Property ID() As Integer
    <JsonProperty("sender_id")>
    Public Property SenderID() As Integer
    <JsonProperty("due_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property DueDate() As DateTime
    <JsonProperty("language_id")>
    Public Property LanguageID() As String
    <JsonProperty("last_event"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastEvent() As DateTime
    <JsonProperty("visible_name")>
    Public Property VisibleName() As String
    <JsonProperty("reminder_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property ReminderDate() As DateTime
    <JsonProperty("offer_status")>
    Public Property OfferStatus() As Integer
    <JsonProperty("offer_type")>
    Public Property OfferType() As Integer
    <JsonProperty("user_details")>
    Public Property UserDetails() As UserDetail
    <JsonProperty("unique_id")>
    Public Property UniqueID() As String
    <JsonProperty("created_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property CreatedDate() As DateTime
    <JsonProperty("signed_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SignedDate() As DateTime
    <JsonProperty("last_sent_emailreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentEmailReminder() As DateTime
    <JsonProperty("last_sent_smsreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentSMSReminder() As DateTime
    <JsonProperty("unread_notification")>
    Public Property UnreadNotification() As Boolean
    <JsonProperty("offer_rejected")>
    Public Property OfferRejected() As Boolean
    <JsonProperty("recieved_by")>
    Public Property RecievedBy() As Boolean
    <JsonProperty("pdf_url")>
    Public Property PdfUrl() As Uri
    <JsonProperty("details")>
    Public Property RecipientDetails() As List(Of InternalDetail)
    <JsonProperty("senderDetails")>
    Public Property SenderDetails() As List(Of InternalDetail)
End Class

Class InternalDetail
    Public Property ID() As Integer
    <JsonProperty("offer_sent_id")>
    Public Property OfferSentID() As Integer
    <JsonProperty("customer_id")>
    Public Property CustomerID() As Integer
    <JsonProperty("offer_status")>
    Public Property OfferStatus() As Integer
    <JsonProperty("sent_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SentDate() As DateTime
    <JsonProperty("email_read_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property EmailReadDate() As DateTime
    <JsonProperty("document_read_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property DocumentReadDate() As DateTime
    <JsonProperty("signed_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SignedDate() As DateTime
    <JsonProperty("reject_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property RejectDate() As DateTime
    <JsonProperty("sender_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property SenderIP() As IPAddress
    <JsonProperty("read_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property ReadIP() As IPAddress
    <JsonProperty("signed_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property SignedIP() As IPAddress
    <JsonProperty("gps_location")>
    Public Property GPSLocation() As String
    <JsonProperty("first_name")>
    Public Property FirstName() As String
    <JsonProperty("last_name")>
    Public Property LastName() As String
    Public Property Company() As String
    <JsonProperty("is_sender")>
    Public Property IsSender() As Boolean
    <JsonProperty("extra_fields")>
    Public Property ExtraFields() As String
    <JsonProperty("user_details")>
    Public Property UserDetails() As UserDetail
    <JsonProperty("request_attachment")>
    Public Property RequestAttachments() As List(Of Object)
    <JsonProperty("pin_code")>
    Public Property PinCode() As Integer
    <JsonProperty("invitation_order")>
    Public Property InvitationOrder() As Integer
    Public Property Email() As String
    <JsonProperty("unique_id")>
    Public Property UniqueID() As String
    Public Property Signature() As String
    <JsonProperty("signature_type")>
    Public Property SignatureType() As String
    <JsonProperty("signature_font")>
    Public Property SignatureFont() As String
End Class

Class UserDetail
    <JsonProperty("first_name")>
    Public Property FirstName() As String
    <JsonProperty("last_name")>
    Public Property LastName() As String
    <JsonProperty("company")>
    Public Property Company() As String
    Public Property Email() As String
    <JsonProperty("reg_no")>
    Public Property RegistrationNumber() As String
    Public Property Address() As String
    Public Property Telephone() As String
    Public Property Mobile() As String
    <JsonProperty("post_code")>
    Public Property PostalCode() As String
    Public Property ZipCode() As String
    Public Property City() As String
    Public Property Country() As String
    <JsonProperty("extra_fields")>
    Public Property ExtraFields() As String
    <JsonProperty("invitation_order")>
    Public Property InvitationOrder() As Integer
    Public Property Confirmation() As Integer
    Public Property Role() As Integer
    <JsonProperty("id_attachment")>
    Public Property IdAttachment() As Integer
    Public Property Authentication() As Integer
    <JsonProperty("paypal_amount")>
    Public Property PaypalAmount() As Decimal
    <JsonProperty("invitation_type")>
    Public Property InvitationType() As Integer
End Class

Class UserSetting
    <JsonProperty("userMsg")>
    Public Property UserMessage() As String
    <JsonProperty("userSMS")>
    Public Property UserSMS() As String
    <JsonProperty("userSubject")>
    Public Property UserSubject() As String
End Class

Class Pagination
    Public Property TotalRecords() As Integer
    Public Property PageLimit() As Integer
    Public Property CurrentPage() As Integer
End Class

Class DataStatistics
    Public Property Sent() As Integer
    Public Property Reviewed() As Integer
    Public Property Signed() As Integer
    Public Property Rejected() As Integer
End Class

Class InvalidDateFormatJsonConverter
    Inherits JsonConverter

    Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
    End Sub

    Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
        Dim result As DateTime
        Try
            If Not DateTime.TryParse(CType(reader.Value, String), result) Then
                result = New DateTime()
            End If
        Catch ex As Exception
            result = New DateTime()
        End Try
        Return result
    End Function

    Public Overrides Function CanConvert(objectType As Type) As Boolean
        Return True
    End Function
End Class

Class IPAddressJsonConverter
    Inherits JsonConverter

    Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
    End Sub

    Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
        Dim result As IPAddress = IPAddress.None
        Try
            If Not IPAddress.TryParse(CType(reader.Value, String), result) Then
                result = IPAddress.None
            End If
        Catch ex As Exception
            result = IPAddress.None
        End Try
        Return result
    End Function

    Public Overrides Function CanConvert(objectType As Type) As Boolean
        Return True
    End Function
End Class

Open in new window

Which gives you this object -Capture.PNG-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter NordbergIT ManagerAuthor Commented:
Hi and thanks for answer,

I elaborated a bit with the code you provided but ended up with an error message.

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IList`1[SimpleSign.Result]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3])

If you look at the JSON below I think you get a better idea on the problem. Under Result there is an array (0,1,2) that seems to be wrongly represented in my classes. I'm not sure how to fix that.

{
    "status": "success",
    "result": {
        "0": {
            "sender_id": 6066,
            "last_event": "2018-11-09 11:45:38",
            "visible_name": "avtal_producenter",
            "offer_status": "Signed",
            "user_details": "{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}",
            "created_date": "2018-11-09 10:16:34",
            "signed_date": "2018-11-09 11:45:38",
            "offer_rejected": "no",
            "name": "avtal_producenter",
            "contract_id": 81147,
            "recipientDetails": [
                {
                    "id": 105665,
                    "customer_id": 43656,
                    "sent_date": "2018-11-09 10:16:38",
                    "document_read_date": "2018-11-09 11:44:15",
                    "signed_date": "2018-11-09 11:45:38",
                    "first_name": "Amanda Goodine",
                    "company": "",
                    "is_sender": "no",
                    "extra_fields": "",
                    "user_details": "{\"full_name\":\"Amanda Goodine\",\"email\":\"amanda@kanal10.se\",\"registerby\":6066,\"mobile\":\"\",\"id\":43656,\"getrecsettings\":1,\"recrolename\":1}",
                    "invitation_order": 1,
                    "email": "amanda@kanal10.se",
                    "offer_confirmation": "email",
                    "invitation_type": "email"
                }
            ],
            "pdf_url": "https://esign.simplesign.io/avtal/downloadpdf/81147/5be5507698e89",
            "senderDetails": [
                {
                    "id": 105664,
                    "customer_id": 0,
                    "sent_date": "2018-11-09 10:16:38",
                    "signed_date": "2018-11-09 10:16:38",
                    "first_name": "Peter Nordberg",
                    "company": "PN Webbutveckling AB",
                    "is_sender": "yes",
                    "extra_fields": "",
                    "user_details": "{\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}",
                    "email": "peter@pnwebbutveckling.se"
                }
            ]
        },
        "1": {
            "sender_id": 6066,
            "last_event": "2018-11-09 10:01:54",
            "visible_name": "ReportBook_1",
            "offer_status": "Reviewed",
            "user_details": "{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}",
            "created_date": "2018-11-09 09:59:57",
            "signed_date": "",
            "offer_rejected": "no",
            "name": "ReportBook_1",
            "contract_id": 81133,
            "recipientDetails": [
                {
                    "id": 105639,
                    "customer_id": 43643,
                    "sent_date": "2018-11-09 09:59:58",
                    "document_read_date": "2018-11-09 10:01:54",
                    "first_name": "Peter Nordberg",
                    "company": "",
                    "is_sender": "no",
                    "extra_fields": "",
                    "user_details": "{\"id\":43643,\"organization_id\":0,\"full_name\":\"Peter Nordberg\",\"email\":\"nordberg.peter@gmail.com\",\"company\":\"\",\"reg_no\":\"\",\"personal_number\":\"\",\"address\":\"\",\"zip\":\"\",\"city\":\"\",\"personnr\":\"\",\"extra_fields\":\"\",\"extra_fields_new\":\"\",\"created_date\":\"2018-11-09 06:22:29\",\"registerby\":6066,\"mobile\":\"\",\"profile_image\":\"\",\"comments\":\"\",\"country\":\"\",\"from_user_api\":0,\"personal_message_status\":0,\"personal_message\":\"\",\"pre_added\":0,\"role_id\":0,\"pre_added_authentication\":0,\"pre_added_details\":null,\"offer_doc_id\":0,\"getrecsettings\":1,\"recrolename\":1}",
                    "invitation_order": 1,
                    "email": "nordberg.peter@gmail.com",
                    "offer_confirmation": "email",
                    "invitation_type": "email"
                }
            ],
            "pdf_url": "https://esign.simplesign.io/avtal/downloadpdf/81133/5be54c8edc8e1",
            "senderDetails": [
                {
                    "id": 105638,
                    "customer_id": 0,
                    "sent_date": "2018-11-09 09:59:58",
                    "signed_date": "2018-11-09 09:59:58",
                    "first_name": "Peter Nordberg",
                    "company": "PN Webbutveckling AB",
                    "is_sender": "yes",
                    "extra_fields": "",
                    "user_details": "{\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}",
                    "email": "peter@pnwebbutveckling.se"
                }
            ]
        },
        "2": {
            "sender_id": 6066,
            "last_event": "2018-11-09 07:23:25",
            "visible_name": "",
            "offer_status": "Signed",
            "user_details": "{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}",
            "created_date": "2018-11-09 07:21:53",
            "signed_date": "2018-11-09 07:23:25",
            "offer_rejected": "no",
            "name": "dummy-pdf_2",
            "contract_id": 81085,
            "recipientDetails": [
                {
                    "id": 105583,
                    "customer_id": 43643,
                    "sent_date": "2018-11-09 07:22:37",
                    "document_read_date": "2018-11-09 07:23:00",
                    "signed_date": "2018-11-09 07:23:25",
                    "first_name": "peter",
                    "company": "",
                    "is_sender": "no",
                    "extra_fields": "",
                    "user_details": "{\"id\":43643,\"full_name\":\"peter\",\"companymandatory\":\"0\",\"reg_nomandatory\":\"0\",\"personnrmandatory\":\"0\",\"mobilemandatory\":\"0\",\"addressmandatory\":\"0\",\"citymandatory\":\"0\",\"zipmandatory\":\"0\",\"email\":\"nordberg.peter@gmail.com\",\"company\":\"\",\"reg_no\":\"\",\"personnr\":\"\",\"mobile\":\"\",\"address\":\"\",\"city\":\"\",\"zipcode\":\"\",\"invitation_order\":\"1\",\"authentication\":1,\"invitation_type\":1,\"role\":1,\"id_attachment\":0,\"confirmation\":1,\"extra_fields\":\"[]\",\"paypal_amount\":0}\r\r\r\r\r\r\r\r\r\r\r\r\r",
                    "request_attachment": "[]",
                    "invitation_order": 1,
                    "email": "nordberg.peter@gmail.com",
                    "offer_confirmation": "email",
                    "invitation_type": "email"
                }
            ],
            "pdf_url": "https://esign.simplesign.io/avtal/downloadpdf/81085/5be527adf10e9",
            "senderDetails": [
                {
                    "id": 105582,
                    "customer_id": 0,
                    "sent_date": "2018-11-09 07:22:37",
                    "signed_date": "2018-11-09 07:22:37",
                    "first_name": "Peter Nordberg",
                    "company": "PN Webbutveckling AB",
                    "is_sender": "yes",
                    "extra_fields": "",
                    "user_details": "{\"id\":6066,\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"city\":\"\",\"country\":\"\",\"zipcode\":\"\",\"mobile\":\"0768153350\"}",
                    "email": "peter@pnwebbutveckling.se"
                }
            ]
        },
        "pagination": {
            "totalRecords": 3,
            "pagelimit": 10,
            "currentpage": 0
        }
    }
}

Open in new window

Peter NordbergIT ManagerAuthor Commented:
When I look it up in the JSON visulizer it looks like this:

JSON visualizer
it_saigeDeveloperCommented:
As I had stated previously, your result object presents as a dictionary, not an array.  Without the pagination (and/or userSetting) object(s), it will convert properly; e.g. -
Imports System.Net
Imports Newtonsoft.Json

Module Module1
    Dim data = "{
        'status': 'success',
        'result': {
            '0': {
                'sender_id': 6066,
                'last_event': '2018-11-09 11:45:38',
                'visible_name': 'avtal_producenter',
                'offer_status': 'Signed',
                'user_details': {'first_name':'Peter Nordberg','last_name':'','company':'PN Webbutveckling AB','email':'peter@pnwebbutveckling.se','reg_no':'','address':'','telephone':'0768153350','post_code':'','city':''},
                'created_date': '2018-11-09 10:16:34',
                'signed_date': '2018-11-09 11:45:38',
                'offer_rejected': 'no',
                'name': 'avtal_producenter',
                'contract_id': 81147,
                'recipientDetails': [
                    {
                        'id': 105665,
                        'customer_id': 43656,
                        'sent_date': '2018-11-09 10:16:38',
                        'document_read_date': '2018-11-09 11:44:15',
                        'signed_date': '2018-11-09 11:45:38',
                        'first_name': 'Amanda Goodine',
                        'company': '',
                        'is_sender': 'no',
                        'extra_fields': '',
                        'user_details': {'full_name':'Amanda Goodine','email':'amanda@kanal10.se','registerby':6066,'mobile':'','id':43656,'getrecsettings':1,'recrolename':1},
                        'invitation_order': 1,
                        'email': 'amanda@kanal10.se',
                        'offer_confirmation': 'email',
                        'invitation_type': 'email'
                    }
                ],
                'pdf_url': 'https://esign.simplesign.io/avtal/downloadpdf/81147/5be5507698e89',
                'senderDetails': [
                    {
                        'id': 105664,
                        'customer_id': 0,
                        'sent_date': '2018-11-09 10:16:38',
                        'signed_date': '2018-11-09 10:16:38',
                        'first_name': 'Peter Nordberg',
                        'company': 'PN Webbutveckling AB',
                        'is_sender': 'yes',
                        'extra_fields': '',
                        'user_details': {'full_name':'Peter Nordberg','email':'peter@pnwebbutveckling.se','company':'PN Webbutveckling AB','reg_no':'','address':'','telephone':'0768153350','post_code':'','city':''},
                        'email': 'peter@pnwebbutveckling.se'
                    }
                ]
            },
            '1': {
                'sender_id': 6066,
                'last_event': '2018-11-09 10:01:54',
                'visible_name': 'ReportBook_1',
                'offer_status': 'Reviewed',
                'user_details': {'first_name':'Peter Nordberg','last_name':'','company':'PN Webbutveckling AB','email':'peter@pnwebbutveckling.se','reg_no':'','address':'','telephone':'0768153350','post_code':'','city':''},
                'created_date': '2018-11-09 09:59:57',
                'signed_date': '',
                'offer_rejected': 'no',
                'name': 'ReportBook_1',
                'contract_id': 81133,
                'recipientDetails': [
                    {
                        'id': 105639,
                        'customer_id': 43643,
                        'sent_date': '2018-11-09 09:59:58',
                        'document_read_date': '2018-11-09 10:01:54',
                        'first_name': 'Peter Nordberg',
                        'company': '',
                        'is_sender': 'no',
                        'extra_fields': '',
                        'user_details': {'id':43643,'organization_id':0,'full_name':'Peter Nordberg','email':'nordberg.peter@gmail.com','company':'','reg_no':'','personal_number':'','address':'','zip':'','city':'','personnr':'','extra_fields':'','extra_fields_new':'','created_date':'2018-11-09 06:22:29','registerby':6066,'mobile':'','profile_image':'','comments':'','country':'','from_user_api':0,'personal_message_status':0,'personal_message':'','pre_added':0,'role_id':0,'pre_added_authentication':0,'pre_added_details':null,'offer_doc_id':0,'getrecsettings':1,'recrolename':1},
                        'invitation_order': 1,
                        'email': 'nordberg.peter@gmail.com',
                        'offer_confirmation': 'email',
                        'invitation_type': 'email'
                    }
                ],
                'pdf_url': 'https://esign.simplesign.io/avtal/downloadpdf/81133/5be54c8edc8e1',
                'senderDetails': [
                    {
                        'id': 105638,
                        'customer_id': 0,
                        'sent_date': '2018-11-09 09:59:58',
                        'signed_date': '2018-11-09 09:59:58',
                        'first_name': 'Peter Nordberg',
                        'company': 'PN Webbutveckling AB',
                        'is_sender': 'yes',
                        'extra_fields': '',
                        'user_details': {'full_name':'Peter Nordberg','email':'peter@pnwebbutveckling.se','company':'PN Webbutveckling AB','reg_no':'','address':'','telephone':'0768153350','post_code':'','city':''},
                        'email': 'peter@pnwebbutveckling.se'
                    }
                ]
            },
            '2': {
                'sender_id': 6066,
                'last_event': '2018-11-09 07:23:25',
                'visible_name': '',
                'offer_status': 'Signed',
                'user_details': {'first_name':'Peter Nordberg','last_name':'','company':'PN Webbutveckling AB','email':'peter@pnwebbutveckling.se','reg_no':'','address':'','telephone':'0768153350','post_code':'','city':''},
                'created_date': '2018-11-09 07:21:53',
                'signed_date': '2018-11-09 07:23:25',
                'offer_rejected': 'no',
                'name': 'dummy-pdf_2',
                'contract_id': 81085,
                'recipientDetails': [
                    {
                        'id': 105583,
                        'customer_id': 43643,
                        'sent_date': '2018-11-09 07:22:37',
                        'document_read_date': '2018-11-09 07:23:00',
                        'signed_date': '2018-11-09 07:23:25',
                        'first_name': 'peter',
                        'company': '',
                        'is_sender': 'no',
                        'extra_fields': '',
                        'user_details': {'id':43643,'full_name':'peter','companymandatory':'0','reg_nomandatory':'0','personnrmandatory':'0','mobilemandatory':'0','addressmandatory':'0','citymandatory':'0','zipmandatory':'0','email':'nordberg.peter@gmail.com','company':'','reg_no':'','personnr':'','mobile':'','address':'','city':'','zipcode':'','invitation_order':'1','authentication':1,'invitation_type':1,'role':1,'id_attachment':0,'confirmation':1,'extra_fields':'[]','paypal_amount':0},
                        'request_attachment': [],
                        'invitation_order': 1,
                        'email': 'nordberg.peter@gmail.com',
                        'offer_confirmation': 'email',
                        'invitation_type': 'email'
                    }
                ],
                'pdf_url': 'https://esign.simplesign.io/avtal/downloadpdf/81085/5be527adf10e9',
                'senderDetails': [
                    {
                        'id': 105582,
                        'customer_id': 0,
                        'sent_date': '2018-11-09 07:22:37',
                        'signed_date': '2018-11-09 07:22:37',
                        'first_name': 'Peter Nordberg',
                        'company': 'PN Webbutveckling AB',
                        'is_sender': 'yes',
                        'extra_fields': '',
                        'user_details': {'id':6066,'full_name':'Peter Nordberg','email':'peter@pnwebbutveckling.se','company':'PN Webbutveckling AB','reg_no':'','address':'','city':'','country':'','zipcode':'','mobile':'0768153350'},
                        'email': 'peter@pnwebbutveckling.se'
                    }
                ]
            }
        },
        'pagination': {
            'totalRecords': 3,
            'pagelimit': 10,
            'currentpage': 0
        }
    }"

    Sub Main()
        Dim converted = JsonConvert.DeserializeObject(Of ResponseMessage)(data)
        Console.WriteLine()
    End Sub
End Module

Class ResponseMessage
    Public Property Status() As String
    Public Property Result() As MessageResult
    Public Property TotalData() As DataStatistics
    Public Property UserSetting() As UserSetting
    Public Property Pagination() As Pagination
End Class

Class MessageResult
    Inherits Dictionary(Of Integer, MessageDetail)
End Class

Class MessageDetail
    Public Property ID() As Integer
    <JsonProperty("sender_id")>
    Public Property SenderID() As Integer
    <JsonProperty("due_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property DueDate() As DateTime
    <JsonProperty("language_id")>
    Public Property LanguageID() As String
    <JsonProperty("last_event"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastEvent() As DateTime
    <JsonProperty("visible_name")>
    Public Property VisibleName() As String
    <JsonProperty("reminder_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property ReminderDate() As DateTime
    <JsonProperty("offer_status")>
    Public Property OfferStatus() As String
    <JsonProperty("offer_type")>
    Public Property OfferType() As Integer
    <JsonProperty("user_details")>
    Public Property UserDetails() As UserDetail
    <JsonProperty("unique_id")>
    Public Property UniqueID() As String
    <JsonProperty("created_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property CreatedDate() As DateTime
    <JsonProperty("signed_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SignedDate() As DateTime
    <JsonProperty("last_sent_emailreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentEmailReminder() As DateTime
    <JsonProperty("last_sent_smsreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentSMSReminder() As DateTime
    <JsonProperty("unread_notification")>
    Public Property UnreadNotification() As String
    <JsonProperty("offer_rejected")>
    Public Property OfferRejected() As String
    <JsonProperty("recieved_by")>
    Public Property RecievedBy() As String
    <JsonProperty("pdf_url")>
    Public Property PdfUrl() As Uri
    <JsonProperty("details")>
    Public Property RecipientDetails() As List(Of InternalDetail)
    <JsonProperty("senderDetails")>
    Public Property SenderDetails() As List(Of InternalDetail)
End Class

Class InternalDetail
    Public Property ID() As Integer
    <JsonProperty("offer_sent_id")>
    Public Property OfferSentID() As Integer
    <JsonProperty("customer_id")>
    Public Property CustomerID() As Integer
    <JsonProperty("offer_status")>
    Public Property OfferStatus() As Integer
    <JsonProperty("sent_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SentDate() As DateTime
    <JsonProperty("email_read_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property EmailReadDate() As DateTime
    <JsonProperty("document_read_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property DocumentReadDate() As DateTime
    <JsonProperty("signed_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SignedDate() As DateTime
    <JsonProperty("reject_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property RejectDate() As DateTime
    <JsonProperty("sender_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property SenderIP() As IPAddress
    <JsonProperty("read_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property ReadIP() As IPAddress
    <JsonProperty("signed_ip"), JsonConverter(GetType(IPAddressJsonConverter))>
    Public Property SignedIP() As IPAddress
    <JsonProperty("gps_location")>
    Public Property GPSLocation() As String
    <JsonProperty("first_name")>
    Public Property FirstName() As String
    <JsonProperty("last_name")>
    Public Property LastName() As String
    Public Property Company() As String
    <JsonProperty("is_sender")>
    Public Property IsSender() As String
    <JsonProperty("extra_fields")>
    Public Property ExtraFields() As String
    <JsonProperty("user_details")>
    Public Property UserDetails() As UserDetail
    <JsonProperty("request_attachment")>
    Public Property RequestAttachments() As List(Of Object)
    <JsonProperty("pin_code")>
    Public Property PinCode() As Integer
    <JsonProperty("invitation_order")>
    Public Property InvitationOrder() As Integer
    Public Property Email() As String
    <JsonProperty("unique_id")>
    Public Property UniqueID() As String
    Public Property Signature() As String
    <JsonProperty("signature_type")>
    Public Property SignatureType() As String
    <JsonProperty("signature_font")>
    Public Property SignatureFont() As String
End Class

Class UserDetail
    <JsonProperty("first_name")>
    Public Property FirstName() As String
    <JsonProperty("last_name")>
    Public Property LastName() As String
    <JsonProperty("company")>
    Public Property Company() As String
    Public Property Email() As String
    <JsonProperty("reg_no")>
    Public Property RegistrationNumber() As String
    Public Property Address() As String
    Public Property Telephone() As String
    Public Property Mobile() As String
    <JsonProperty("post_code")>
    Public Property PostalCode() As String
    Public Property ZipCode() As String
    Public Property City() As String
    Public Property Country() As String
    <JsonProperty("extra_fields")>
    Public Property ExtraFields() As String
    <JsonProperty("invitation_order")>
    Public Property InvitationOrder() As Integer
    Public Property Confirmation() As Integer
    Public Property Role() As Integer
    <JsonProperty("id_attachment")>
    Public Property IdAttachment() As Integer
    Public Property Authentication() As Integer
    <JsonProperty("paypal_amount")>
    Public Property PaypalAmount() As Decimal
    <JsonProperty("invitation_type")>
    Public Property InvitationType() As Integer
End Class

Class UserSetting
    <JsonProperty("userMsg")>
    Public Property UserMessage() As String
    <JsonProperty("userSMS")>
    Public Property UserSMS() As String
    <JsonProperty("userSubject")>
    Public Property UserSubject() As String
End Class

Class Pagination
    Public Property TotalRecords() As Integer
    Public Property PageLimit() As Integer
    Public Property CurrentPage() As Integer
End Class

Class DataStatistics
    Public Property Sent() As Integer
    Public Property Reviewed() As Integer
    Public Property Signed() As Integer
    Public Property Rejected() As Integer
End Class

Class InvalidDateFormatJsonConverter
    Inherits JsonConverter

    Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
    End Sub

    Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
        Dim result As DateTime
        Try
            If Not DateTime.TryParse(CType(reader.Value, String), result) Then
                result = New DateTime()
            End If
        Catch ex As Exception
            result = New DateTime()
        End Try
        Return result
    End Function

    Public Overrides Function CanConvert(objectType As Type) As Boolean
        Return True
    End Function
End Class

Class IPAddressJsonConverter
    Inherits JsonConverter

    Public Overrides Sub WriteJson(writer As JsonWriter, value As Object, serializer As JsonSerializer)
    End Sub

    Public Overrides Function ReadJson(reader As JsonReader, objectType As Type, existingValue As Object, serializer As JsonSerializer) As Object
        Dim result As IPAddress = IPAddress.None
        Try
            If Not IPAddress.TryParse(CType(reader.Value, String), result) Then
                result = IPAddress.None
            End If
        Catch ex As Exception
            result = IPAddress.None
        End Try
        Return result
    End Function

    Public Overrides Function CanConvert(objectType As Type) As Boolean
        Return True
    End Function
End Class

Open in new window

Which produces the following results -Capture.PNG-saige-
Peter NordbergIT ManagerAuthor Commented:
Hi and thanks for answer,

I can see the result as shown in your image above and have been successful in using it, but why are the result of recepientDetails nothiing while the senderDetails are populated? They both have data in the json string.

Thanks for help!

Peter
it_saigeDeveloperCommented:
What does your current json string look like?

-saige-
Peter NordbergIT ManagerAuthor Commented:
Like this when I get it directly from the api request:

{"status":"success","result":{"0":{"sender_id":6066,"last_event":"2018-11-09 11:45:38","visible_name":"avtal_producenter","offer_status":"Signed","user_details":"{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}","created_date":"2018-11-09 10:16:34","signed_date":"2018-11-09 11:45:38","offer_rejected":"no","name":"avtal_producenter","contract_id":81147,"recipientDetails":[{"id":105665,"customer_id":43656,"sent_date":"2018-11-09 10:16:38","document_read_date":"2018-11-09 11:44:15","signed_date":"2018-11-09 11:45:38","first_name":"Amanda Goodine","company":"","is_sender":"no","extra_fields":"","user_details":"{\"full_name\":\"Amanda Goodine\",\"email\":\"amanda@kanal10.se\",\"registerby\":6066,\"mobile\":\"\",\"id\":43656,\"getrecsettings\":1,\"recrolename\":1}","invitation_order":1,"email":"amanda@kanal10.se","offer_confirmation":"email","invitation_type":"email"}],"pdf_url":"https:\/\/esign.simplesign.io\/avtal\/downloadpdf\/81147\/5be5507698e89","senderDetails":[{"id":105664,"customer_id":0,"sent_date":"2018-11-09 10:16:38","signed_date":"2018-11-09 10:16:38","first_name":"Peter Nordberg","company":"PN Webbutveckling AB","is_sender":"yes","extra_fields":"","user_details":"{\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}","email":"peter@pnwebbutveckling.se"}]},"1":{"sender_id":6066,"last_event":"2018-11-09 10:01:54","visible_name":"ReportBook_1","offer_status":"Reviewed","user_details":"{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}","created_date":"2018-11-09 09:59:57","signed_date":"","offer_rejected":"no","name":"ReportBook_1","contract_id":81133,"recipientDetails":[{"id":105639,"customer_id":43643,"sent_date":"2018-11-09 09:59:58","document_read_date":"2018-11-09 10:01:54","first_name":"Peter Nordberg","company":"","is_sender":"no","extra_fields":"","user_details":"{\"id\":43643,\"organization_id\":0,\"full_name\":\"Peter Nordberg\",\"email\":\"nordberg.peter@gmail.com\",\"company\":\"\",\"reg_no\":\"\",\"personal_number\":\"\",\"address\":\"\",\"zip\":\"\",\"city\":\"\",\"personnr\":\"\",\"extra_fields\":\"\",\"extra_fields_new\":\"\",\"created_date\":\"2018-11-09 06:22:29\",\"registerby\":6066,\"mobile\":\"\",\"profile_image\":\"\",\"comments\":\"\",\"country\":\"\",\"from_user_api\":0,\"personal_message_status\":0,\"personal_message\":\"\",\"pre_added\":0,\"role_id\":0,\"pre_added_authentication\":0,\"pre_added_details\":null,\"offer_doc_id\":0,\"getrecsettings\":1,\"recrolename\":1}","invitation_order":1,"email":"nordberg.peter@gmail.com","offer_confirmation":"email","invitation_type":"email"}],"pdf_url":"https:\/\/esign.simplesign.io\/avtal\/downloadpdf\/81133\/5be54c8edc8e1","senderDetails":[{"id":105638,"customer_id":0,"sent_date":"2018-11-09 09:59:58","signed_date":"2018-11-09 09:59:58","first_name":"Peter Nordberg","company":"PN Webbutveckling AB","is_sender":"yes","extra_fields":"","user_details":"{\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}","email":"peter@pnwebbutveckling.se"}]},"2":{"sender_id":6066,"last_event":"2018-11-09 07:23:25","visible_name":"","offer_status":"Signed","user_details":"{\"first_name\":\"Peter Nordberg\",\"last_name\":\"\",\"company\":\"PN Webbutveckling AB\",\"email\":\"peter@pnwebbutveckling.se\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"0768153350\",\"post_code\":\"\",\"city\":\"\"}","created_date":"2018-11-09 07:21:53","signed_date":"2018-11-09 07:23:25","offer_rejected":"no","name":"dummy-pdf_2","contract_id":81085,"recipientDetails":[{"id":105583,"customer_id":43643,"sent_date":"2018-11-09 07:22:37","document_read_date":"2018-11-09 07:23:00","signed_date":"2018-11-09 07:23:25","first_name":"peter","company":"","is_sender":"no","extra_fields":"","user_details":"{\"id\":43643,\"full_name\":\"peter\",\"companymandatory\":\"0\",\"reg_nomandatory\":\"0\",\"personnrmandatory\":\"0\",\"mobilemandatory\":\"0\",\"addressmandatory\":\"0\",\"citymandatory\":\"0\",\"zipmandatory\":\"0\",\"email\":\"nordberg.peter@gmail.com\",\"company\":\"\",\"reg_no\":\"\",\"personnr\":\"\",\"mobile\":\"\",\"address\":\"\",\"city\":\"\",\"zipcode\":\"\",\"invitation_order\":\"1\",\"authentication\":1,\"invitation_type\":1,\"role\":1,\"id_attachment\":0,\"confirmation\":1,\"extra_fields\":\"[]\",\"paypal_amount\":0}\r\r\r\r\r\r\r\r\r\r\r\r\r","request_attachment":"[]","invitation_order":1,"email":"nordberg.peter@gmail.com","offer_confirmation":"email","invitation_type":"email"}],"pdf_url":"https:\/\/esign.simplesign.io\/avtal\/downloadpdf\/81085\/5be527adf10e9","senderDetails":[{"id":105582,"customer_id":0,"sent_date":"2018-11-09 07:22:37","signed_date":"2018-11-09 07:22:37","first_name":"Peter Nordberg","company":"PN Webbutveckling AB","is_sender":"yes","extra_fields":"","user_details":"{\"id\":6066,\"full_name\":\"Peter Nordberg\",\"email\":\"peter@pnwebbutveckling.se\",\"company\":\"PN Webbutveckling AB\",\"reg_no\":\"\",\"address\":\"\",\"city\":\"\",\"country\":\"\",\"zipcode\":\"\",\"mobile\":\"0768153350\"}","email":"peter@pnwebbutveckling.se"}]},"pagination":{"totalRecords":3,"pagelimit":10,"currentpage":0}}}

Open in new window

Peter NordbergIT ManagerAuthor Commented:
Hi, did you get any insight in why the recepientDetails  is nothing?

Peter
it_saigeDeveloperCommented:
I found the reason.  It's because the property name changed from details to recipientDetails.  Simply update the JsonProperty attribute in the MessageDetail class for the RecipientDetails property -
Class MessageDetail
    Public Property ID() As Integer
    <JsonProperty("sender_id")>
    Public Property SenderID() As Integer
    <JsonProperty("due_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property DueDate() As DateTime
    <JsonProperty("language_id")>
    Public Property LanguageID() As String
    <JsonProperty("last_event"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastEvent() As DateTime
    <JsonProperty("visible_name")>
    Public Property VisibleName() As String
    <JsonProperty("reminder_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property ReminderDate() As DateTime
    <JsonProperty("offer_status")>
    Public Property OfferStatus() As String
    <JsonProperty("offer_type")>
    Public Property OfferType() As Integer
    <JsonProperty("user_details")>
    Public Property UserDetails() As UserDetail
    <JsonProperty("unique_id")>
    Public Property UniqueID() As String
    <JsonProperty("created_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property CreatedDate() As DateTime
    <JsonProperty("signed_date"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property SignedDate() As DateTime
    <JsonProperty("last_sent_emailreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentEmailReminder() As DateTime
    <JsonProperty("last_sent_smsreminder"), JsonConverter(GetType(InvalidDateFormatJsonConverter))>
    Public Property LastSentSMSReminder() As DateTime
    <JsonProperty("unread_notification")>
    Public Property UnreadNotification() As String
    <JsonProperty("offer_rejected")>
    Public Property OfferRejected() As String
    <JsonProperty("recieved_by")>
    Public Property RecievedBy() As String
    <JsonProperty("pdf_url")>
    Public Property PdfUrl() As Uri
    <JsonProperty("recipientDetails")>
    Public Property RecipientDetails() As List(Of InternalDetail)
    <JsonProperty("senderDetails")>
    Public Property SenderDetails() As List(Of InternalDetail)
End Class

Open in new window

Should now give the RecipientDetails.

-saige-
Peter NordbergIT ManagerAuthor Commented:
Super! Thanks!

I will make your answer my solution. Now when I have you on the thread can I just ask one more thing: I get this error when I get the json string that I posted above:

Newtonsoft.Json.JsonSerializationException
  HResult=0x80131500
  Message=Error converting value "{"first_name":"Peter Nordberg","last_name":"","company":"PN Webbutveckling AB","email":"peter@pnwebbutveckling.se","reg_no":"","address":"","telephone":"0768153350","post_code":"","city":""}" to type 'UserDetail'. Path 'result.0.user_details', line 1, position 389.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at History.History_Load(Object sender, EventArgs e) in C:\Users\peter\OneDrive\Websiter\SimpleSign\SimpleSign\History.aspx.vb:line 14

Inner Exception 1:
ArgumentException: Could not cast or convert from System.String to UserDetail.

How can I change that from a string to the UserDetail Object?

If I comment out that it all works fine, but it would be nice to have that information solved to.

Thanks,

Peter
Peter NordbergIT ManagerAuthor Commented:
Thanks for your help, I really appciciate it!

Peter
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.