Home > Back-end >  .net Desearialize Object to Json with '.' in field
.net Desearialize Object to Json with '.' in field

Time:08-18

I created an object to deseralize. I need to JSON data to an API. In the API one of the fields has a period in it. Here is the required JSON request body

{
 "first_name" : "john"
 "last_name" : "doe"
 "member.id" : "1234"
}

Here is my VB Object

Public Class Person
 Public first_name As String
 Public last_name As String
 Public MemberId As String
End Class

When I use the Newtonsoft.Json library to deserialize it doesn't have the period (.). How can I deserialize it to achieve what the API requires.

CodePudding user response:

try add JsonProperty name attributes

Public Class Person

<JsonProperty("first_name")>
 Public FirstName As String

<JsonProperty("last_name")>
 Public LastName As String

 <JsonProperty("member.id")>
 Public MemberId As String

End Class
  • Related