Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:17:31+00:00 2026-06-13T07:17:31+00:00

I am receiving JSON data to my server with dates represented like this: {

  • 0

I am receiving JSON data to my server with dates represented like this:

{
    "startDate": {
        "d": "/Date(1346454000000)/"
    },
    "slots": [
        {
            "d": "/Date(1347058800000)/"
        },
        {
            "d": "/Date(1347145200000)/"
        }
    ]
}

Its serialized to a simple object:

public class SlotsVm
{
    public DateTime StartDate { get; set; }

    public DateTime[] Slots { get; set; }
}

Because the date format is strange, I had to write a custom JsonConverter to process it. To deserialize, I use code like this:

var slotsVm = JsonConvert.DeserializeObject<SlotsVm>(body,
    new CustomDateTimeConverter());

If possible, I would like the need for the converter to be defined on the SlotsVm class, rather than in the code that actually makes the conversion. This is possible for the startDate property using attributes:

[JsonConverter(typeof(CustomDateTimeConverter))]
public DateTime StartDate { get; set; }

but it is not possible for Slots, which is an array instead of a simple DateTime.

It would be best for me to be able to define the converters that the class needs on the class itself:

[JsonConverters(typeof(CustomDateTimeConverter), ...]
public class PutDealVm
{

}

but there doesn’t seem to be a way to do this.

Can you think of a solution? Is there some way to define converters for a class that I have missed? Alternatively, is it possible to define the converter that an array should user for each of its elements?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:17:32+00:00Added an answer on June 13, 2026 at 7:17 am

    What about something like this? I appreciate that this may not directly answer your question, but I was too lazy to recreate the CustomDateTimeConverter class, so came up with this instead, which is arguably simpler, as there is no need for a custom converter.

    string json = "{\"startDate\": {\"d\": \"/Date(1346454000000)/\"},\"slots\": [{\"d\": \"/Date(1347058800000)/\"},{\"d\": \"/Date(1347145200000)/\"}]}";
    
    SlotsVmDeserialized slotsVmDeserialized =
        JsonConvert.DeserializeObject<SlotsVmDeserialized>(json);
    
    SlotsVm slotsVm = new SlotsVm()
    {
        Slots = slotsVmDeserialized.Slots.Select(d => d.Date),
        StartDate = slotsVmDeserialized.StartDate.Date
    };
    
    ....
    
    public class SlotsVm
    {
        public DateTime StartDate { get; set; }
        public IEnumerable<DateTime> Slots { get; set; }
    }
    
    public class SlotsVmDeserialized
    {
        public DateObject StartDate { get; set; }
        public IEnumerable<DateObject> Slots { get; set; }
    }
    
    public class DateObject
    {
        [JsonProperty("d")]
        public DateTime Date { get; set; }
    }
    

    What I’ve done here is firstly deserialized to the SlotsVmDeserialized class, which is used to hold a single DataObject and an IEnumerable of them. The DateObject class is essentially my alternative/workaround to the custom converter. I could have done all this without any attributes by removing [JsonProperty("d")] and renaming Data to D.

    Once deserialized, I then create a new SlotsVm object based on the properties of the SlotsVmDeserialized object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sending some data to the server and receiving the response as JSON.
After my last question was solved the JSON I'm receiving from the server changed
I am using a web service that returns JSON data. test.com/incident.do?JSON&sysparm_action=getRecords Loading this URL
I'm sending a json string to a REST server and receiving one in return,
When I sync for edited grid, extjs pass JSON data to Server by AJAX.
I am receiving JSON Data from a client application, but once in a while
I am receiving JSON-Data and convert it into a Dictionary. Printing the Dictionary results
Occasionally I'm querying a server for JSON and receiving a 404 HTML page when
I'm sending json-formatted data to my Java server via http requests. I've had great
Receiving and sending data with JSON is done with simple HTTP requests. Whereas in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.