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 7887707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:39:02+00:00 2026-06-03T05:39:02+00:00

I have been looking at a few posts on SO about how to deserialize

  • 0

I have been looking at a few posts on SO about how to deserialize a date in a json string.

The posts mention doing a replace on the string to reformat the Date parts.

the json string looks like this:

"/Date(1336258800000)/\"

apparently what I need to get to is this:

"new Date(1336258800000)"

The trouble is as soon as I try and to a replace, or indexOf ‘)/\’ it doesnt find the string to replace (indexOf is -1)

can anyone see what im doing wrong?

                    JavaScriptSerializer jss = new JavaScriptSerializer();

                    //Fix an issue with Json Dates
                    string json = eventArgument.Replace( @"/Date(", "new Date(" ).Replace( @")/\", ")" );

                    int index = json.IndexOf( @")/\", 0 );

                    WorkPattern wp = jss.DeserializeObject( json ) as WorkPattern;

here is the full json string:

"{\"WorkPatternDays\":[{\"WorkPatternDayShifts\":[{\"WorkPatternDayShiftRates\":[{\"Duration\":8.5,\"Sequence\":0,\"WorkPatternDayShiftID\":186,\"WorkPatternDayShiftRateID\":105,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"WorkPatternDayShiftBreaks\":[{\"PaidBreak\":true,\"Duration\":1,\"EndTime\":\"/Date(1336050000000)/\",\"StartTime\":\"/Date(1336046400000)/\",\"WorkPatternDayShiftID\":186,\"WorkPatternDayShiftBreakID\":284,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"},{\"PaidBreak\":false,\"Duration\":0.25,\"EndTime\":\"/Date(1336058100000)/\",\"StartTime\":\"/Date(1336057200000)/\",\"WorkPatternDayShiftID\":186,\"WorkPatternDayShiftBreakID\":285,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"Duration\":8.5,\"EndTime\":\"/Date(1336062600000)/\",\"StartTime\":\"/Date(1336032000000)/\",\"WorkPatternDayID\":186,\"WorkPatternDayShiftID\":186,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"DayOfWeek\":1,\"DayOfWeekNumber\":1,\"WorkPatternID\":105,\"WorkPatternDayID\":186,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"},{\"WorkPatternDayShifts\":[{\"WorkPatternDayShiftRates\":[],\"WorkPatternDayShiftBreaks\":[{\"PaidBreak\":true,\"Duration\":0.5,\"EndTime\":\"/Date(1336041000000)/\",\"StartTime\":\"/Date(1336039200000)/\",\"WorkPatternDayShiftID\":187,\"WorkPatternDayShiftBreakID\":286,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"Duration\":5.5,\"EndTime\":\"/Date(1336046400000)/\",\"StartTime\":\"/Date(1336026600000)/\",\"WorkPatternDayID\":187,\"WorkPatternDayShiftID\":187,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"DayOfWeek\":3,\"DayOfWeekNumber\":3,\"WorkPatternID\":105,\"WorkPatternDayID\":187,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}],\"WorkPatternName\":\"Naths Test Work Pattern\",\"WorkPatternID\":105,\"Deleted\":false,\"UpdatedUser\":\"\",\"UpdatedDate\":\"/Date(1336258800000)/\"}"

A bit more info to see how it all fits together:

code behind:

        public override void DataBind()
        {
            try
            {
                if ( this.WorkPattern != null )
                {
                    //Create a javascript serializer
                    JavaScriptSerializer jss = new JavaScriptSerializer();

                    //Get the serialised object as a json string
                    string json = jss.Serialize( this.WorkPattern );

                    //Run the jquery code
                    base.RunjQueryCode(
                        String.Format( "loadWorkPattern({0});", json ) );

                    jss = null;
                }
            }
            catch ( Exception )
            {

                throw;
            }
        }

 protected override void HandlePostbacks( string eventTarget, string eventArgument )
        {
            try
            {
                switch ( eventTarget )
                {
                    case "Save":

                        JavaScriptSerializer jss = new JavaScriptSerializer();

                        //Fix an issue with Json Dates
                        string json = eventArgument.Replace( @"/Date(", "new Date(" ).Replace( @")/\", ")" );

                        int index = json.IndexOf( @")/\\", 0 );

                        WorkPattern wp = jss.DeserializeObject( json ) as WorkPattern;


                        object o = jss.Deserialize<WorkPattern>( json );


                        break;
                    default: break;
                }

                base.HandlePostbacks( eventTarget, eventArgument );
            }
            catch ( Exception )
            {
                throw;
            }
        }

Markup / js:

function loadWorkPattern(jsonData) {

        //Store the work pattern
        _workPattern = jsonData;

        //Loop through the work pattern days
        $.each(_workPattern.WorkPatternDays, function (key, workPatternDay) {

            //Loop through each shift
            $.each(workPatternDay.WorkPatternDayShifts, function (key, workPatternShift) {
                addShift(workPatternShift, workPatternDay.DayOfWeekNumber);

                //Loop through each break
                $.each(workPatternShift.WorkPatternDayShiftBreaks, function (key, workPatternDayShiftBreak) {
                    addBreak(workPatternDayShiftBreak);
                });
            });
        });
    }

    function saveWorkPattern() {
        __doPostBack('Save', JSON.stringify(_workPattern));
    }

Im calling JSON.stringify to serialize the serialize the stored object before sending back to the server, is this what im doing wrong?

UPDATE

This is the working code:

string json = eventArgument.Replace( @"/Date(", "\\/Date(" ).Replace( @")/", ")\\/" );
  • 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-03T05:39:03+00:00Added an answer on June 3, 2026 at 5:39 am

    Try int index = json.IndexOf( @")/\\", 0 ); – put another slash before the slash

    Update

    JavaScriptSerializer s = new JavaScriptSerializer();
    string date = s.Serialize(DateTime.Now);
    int index = date.IndexOf(@")\/", 0);
    Console.WriteLine(index); // index = 21
    

    Update – solution

    The problem is the the initial string is /Date(1336258800000)/, but not /Date(1336258800000)/\ as the last slash is an escape of the " character in the JSON.
    And the format for the desiarization should be dirrerent, so the working solution is

    string json = eventArgument.Replace( @"/Date(", "\\/Date(" ).Replace( @")/", ")\\/" );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been able to find a few posts on StackOverflow about how to control
I have been looking at monads a lot over the past few months (functors
I am new to java and have been looking at few tutorials around GIS
I have been looking at a few of our VB.NET dll's using FxCop and
Over the last few weeks i have been looking at solutions to share an
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking into benchmarking lately, I have always been interested in logging
i have been looking around to try and work out how to pass 2
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance

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.