Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Have an interesting project here. I am trying to write an app to go onto a Motorola scanner that runs .Net Compact 3.5. I have to work with a REST API and am having issues with Deserializing the json to the classes that I have written using Json.Net 3.5 R8 (this is the last version of Json.Net that supported .Net Compact). Below is the classes that I have written:

VB
Public Class ResponseProperties
    Public Property Status() As String
        Get
            Return m_Status
        End Get
        Set(ByVal value As String)
            m_Status = value
        End Set
    End Property
    Private m_Status As String
    Public Property Nsid() As String
        Get
            Return m_Nsid
        End Get
        Set(ByVal value As String)
            m_Nsid = value
        End Set
    End Property
    Private m_Nsid As String
    Public Property Message() As String
        Get
            Return m_Message
        End Get
        Set(ByVal value As String)
            m_Message = value
        End Set
    End Property
    Private m_Message As String
    Public Property RecordType() As String
        Get
            Return m_RecordType
        End Get
        Set(ByVal value As String)
            m_RecordType = value
        End Set
    End Property
    Private m_RecordType As String
    Public Property BinNumber() As String
        Get
            Return m_BinNumber
        End Get
        Set(ByVal value As String)
            m_BinNumber = value
        End Set
    End Property
    Private m_BinNumber As String
    Public Property ExternalID() As Integer
        Get
            Return m_ExternalID
        End Get
        Set(ByVal value As Integer)
            m_ExternalID = value
        End Set
    End Property
    Private m_ExternalID As Integer
End Class

Public Class Response
    Public Property responce() As ResponseProperties()
        Get
            Return m_responce
        End Get
        Set(ByVal value As ResponseProperties())
            m_responce = value
        End Set
    End Property
    Private m_responce As ResponseProperties()
End Class


and here is the code that I am using to deserialize the json:

VB
Imports Newtonsoft.Json
Imports System.Net
Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim Json As String = txtjson.Text 
        Dim ResponcesRes = JsonConvert.DeserializeObject(Of Response)(Json)
        lblOutput.Text = "output" & vbNewLine & ResponcesRes.responce(1).BinNumber

    End Sub

End Class


Here is an example of the Json that I am receiving.

{"response":[{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111},{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111},{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111},{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111},{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111},{"status":"success","nsid":"22222","message":"message here","recordtype":"bin","type":"create","binnumber":"binname","externalid":1111}]}

The code does not Error I Just don't get any output. if i=I hover the mouse over the ResponcesRes it tells me that it contains Nothing.
If there is more information needed please ask.

What I have tried:

Have tried to changed the Class Structure but this has not helped resolve the issue.
Posted
Updated 14-Jun-17 11:35am

1 solution

Quote:
Public Property responce() As ResponseProperties()
{"response":[

In your sample JSON, the property is called response, not responce.

Try changing the property name to match the JSON.
 
Share this answer
 
Comments
Aneets 15-Jun-17 4:01am    
Thanks So Much Richard. I cant believe that I made that mistake.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900