Results 1 to 3 of 3

Thread: [RESOLVED] JSON returns "date" property

  1. #1

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    Resolved [RESOLVED] JSON returns "date" property

    I'm pulling data from an API that returns a JSON "property?" that's called "date". Obviously, this is a protected namespace, so I get an error on this line of code:
    Code:
       Public Property date As DateTimeOffset
    Since I can't change what's coming back from the API request - how would I handle this in my code so that I can retrieve the "date" value from the API request?


    -Matthew-

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: JSON returns "date" property

    One option is to wrap the property name in square brackets:
    Code:
    Public Property [date] As DateTimeOffset
    A better option would be to use decorators to point the name in the incoming JSON to date, but name the property something else in your class:
    Code:
    <JsonProperty("date")>
    Public Property MyDateProperty As DateTimeOffset
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    Re: JSON returns "date" property

    Quote Originally Posted by dday9 View Post
    One option is to wrap the property name in square brackets:
    Code:
    Public Property [date] As DateTimeOffset
    A better option would be to use decorators to point the name in the incoming JSON to date, but name the property something else in your class:
    Code:
    <JsonProperty("date")>
    Public Property MyDateProperty As DateTimeOffset
    Thanks! That worked!


    -Matthew-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width