×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VB.NET Program - problems deserializing JSON into List of objects

VB.NET Program - problems deserializing JSON into List of objects

VB.NET Program - problems deserializing JSON into List of objects

(OP)
Hello All-
I am hoping someone may be able to help me figure this out. I am querying something via an API call, and it does return a list of items in its RawJSON. Right now my code does that much correctly, but I'm having difficulty turning that into a list of ServerRecord objects. Please see my code below and let me know if you have any tips for me on what I am messing up. Please let me know if you need any more information in order to help me out. Thanks in advance!


CODE --> VB.Net

Public Class ServerRecord
        Inherits Record
        <Newtonsoft.Json.JsonProperty("sys_class_name")>
        Public Property sys_class_name As String
            Get
            End Get
            Set(value As String)
            End Set
        End Property


        <Newtonsoft.Json.JsonProperty("host_name")>
        Public Property host_name As String
            Get
            End Get
            Set(value As String)
            End Set
        End Property
        <Newtonsoft.Json.JsonProperty("u_recovery_time_achievable")>
        Public Property u_recovery_time_achievable As String
            Get
            End Get
            Set(value As String)
            End Set
        End Property
    End Class


        Dim lstSNServersList As New List(Of ServerRecord)
        Dim objServiceNowTableAPIClient As TableAPI.TableAPIClient(Of ServerRecord)
        Dim objServiceNowRESTQueryResponse As RESTQueryResponse(Of ServerRecord)

            objServiceNowTableAPIClient = New TableAPIClient(Of wServerRecord)(strServiceNowCMDBServersTableName, strServiceNowInstanceName, strServiceNowUser, strServiceNowPassword)
            strServiceNowQuery = "sys_class_name=cmdb_ci_win_server^ORsys_class_name=cmdb_ci_linux_server"
            objServiceNowRESTQueryResponse = objServiceNowTableAPIClient.GetByQuery(strServiceNowQuery)
            'this much does work and it does return a result set

            'this is my attempt to convert this response into a list of ServerRecords, but this does not work currently:
            lstSNServersList = JsonConvert.DeserializeObject(Of List(Of ServerRecord))(objServiceNowRESTQueryResponse.RawJSON) 

The objServiceNowRestQueryResponse.RawJSON string looks like this (though much longer):
"{""result"":[{""sys_id"":""00040665dbxxxxxx96191e"",""u_recovery_time_achievable"":""720"",""sys_class_name"":""cmdb_ci_linux_server"",""host_name"":""rlserver001""},{""sys_id"":""00ec543d1xxxx66e4bcb6d"",""u_recovery_time_achievable"":""4"",""sys_class_name"":""cmdb_ci_linux_server"",""host_name"":""plserver001""},{""sys_id"":""0105d975dbxxxxx8961998"",""u_recovery_time_achievable"":"""",""sys_class_name"":""cmdb_ci_linux_server"",""host_name"":""tlserver001""},


This is the error message I get when trying to run my code:
Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll
The thread 0x20b4 has exited with code 0 (0x0).
The thread 0x3e24 has exited with code 0 (0x0).
The program '[5892] CMDBReconciliation.vshost.exe' has exited with code 0 (0x0).


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close