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

  • Home
  • SEARCH
  • 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 8215319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:44:42+00:00 2026-06-07T11:44:42+00:00

I’m attempting to parse JSON response to convert ASP.NET dates to javascript dates. The

  • 0

I’m attempting to parse JSON response to convert ASP.NET dates to javascript dates.

The actual response looks like so:

{"Id":1,"Title":null,"Description":null,"Content":null,"PropagateModel":false,"Status":0,"ComponentPublishDate":"\/Date(1340299653555)\/"}

I extended the javascript string object to do the regex conversion from \/Date(1340299653555)\/ to new Date(1340298914781)

String.prototype.parseWithJSONDate = function () {
   return this.replace(/\/Date\((.*?)\)\//gi, 'new Date($1)');
};

Then i setup a converter filter to do the actual parsing.

    $.ajaxSetup({
      dataFilter: function(data, dataType) {
        if (dataType === "json") {
          return data.parseWithJSONDate();
        }
        return data;
      }
    });

This converter doesn’t work. The first issue i had with it was that the response would get corrupted somehow after the converter returns. I fixed that by calling JSON.parse like so return JSON.parse(res) at the end of function. Why in the world do i need to parse a string that’s already a JSON string??

The second issue is that actual regex doesn’t appear to be replacing values. The odd thing is i tested it outside of the function on a sample JSON string and it worked just fine.

Can anybody suggest anything? Thanks!

UPDATE 1
I think i figured out the answer to my first question. My converter was running for json and text data types. Which is likely the reason why i had to explicitly convert the return value to JSON. I removed text data type from the converter and updated the rest of the code accordingly.

UPDATE 2
I ended up creating a new view model where date is a formatted string. Not the best thing in world, but better than screwing around with jQuery ajax events.

  • 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-07T11:44:43+00:00Added an answer on June 7, 2026 at 11:44 am

    I ended up converting all dates to appropriate format on the server and returning the value to client. Not the optimal solution, but i couldn’t figure out how to convert with data filters.

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.