0

I am in the process of deserializing a JSON string with VB.NET. I am using JSON.NET and have made a custom class to use with JsonConvert.DeserializeObject function. The only issue I have is one of the values coming through the JSON string is called 'stop'. This causes the VB.NET to not compile, owing to the fact you cannot declare a value with the name 'stop'. When I change the value of 'stop' to something else, the data from the 'stop' value is no longer read from the JSON string. I have been trying to work out how to get around this, but short of changing the JSON string response, which I unfortunately cannot do, I have come up short. Any help would be most appreciated.

Public Class GuideEntry
    Public Property eventId As Integer
    Public Property episodeId As Integer
    Public Property serieslinkId As Integer
    Public Property serieslinkUri As String
    Public Property channelName As String
    Public Property channelUuid As String
    Public Property channelNumber As String
    Public Property start As Integer
    Public Property stop As Integer 'JSON value causing the problem
    Public Property title As String
    Public Property description As String
    Public Property genre As Integer()
    Public Property nextEventId As Integer
    Public Property episodeUri As String
    Public Property episodeNumber As Integer
    Public Property episodeOnscreen As String
    Public Property subtitle As String
    Public Property partNumber As Integer
    Public Property partCount As Integer
    Public Property starRating As Integer
End Class
Nick
  • 58
  • 1
  • 4
  • Already answered http://stackoverflow.com/questions/8796618/how-can-i-change-property-names-when-serializing-with-json-net – Remus Rusanu Jul 26 '15 at 13:54

2 Answers2

1

Change the name of your stop property

<JsonProperty("stop")> _
Public Property anythingButStop As String
Arthur Rey
  • 2,990
  • 3
  • 19
  • 42
1

Adding to Arthurs' answer,

VB Code would be something like this.

Public Class GuideEntry
    Public Property eventId As Integer
    Public Property episodeId As Integer
    Public Property serieslinkId As Integer
    Public Property serieslinkUri As String
    Public Property channelName As String
    Public Property channelUuid As String
    Public Property channelNumber As String
    Public Property start As Integer

    <JsonProperty("stop")> _
    Public Property stopValue As Integer 'JSON value causing the problem

    Public Property title As String
    Public Property description As String
    Public Property genre As Integer()
    Public Property nextEventId As Integer
    Public Property episodeUri As String
    Public Property episodeNumber As Integer
    Public Property episodeOnscreen As String
    Public Property subtitle As String
    Public Property partNumber As Integer
    Public Property partCount As Integer
    Public Property starRating As Integer
End Class

Here is .net fiddle link

Sameer Azazi
  • 1,503
  • 10
  • 16