Created
September 6, 2010 17:20
-
-
Save andrewdavey/567285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.parseJSON = (function(parse) { | |
var datePattern = /^\/Date\((\d+)\)\/$/; | |
return function(data) { | |
var value = parse(data); | |
parseDates(value); | |
return value; | |
} | |
function parseDates(obj) { | |
for (var k in obj) { | |
if (!obj.hasOwnProperty(k)) continue; | |
var value = obj[k]; | |
if (typeof value === 'string') { | |
var match = value.match(datePattern); | |
if (match) obj[k] = new Date(parseInt(match[1])); | |
} else if (value instanceof Object) { | |
parseDates(value); | |
} | |
} | |
} | |
})(jQuery.parseJSON); |
@varInt feel free to fork if you want to add comments ;)
show example ..., I do not understand
jQuery's parseJSON function does not support converting dates represented in "/Date(1234567)/" format into Date objects.
This gist shows how to override the parseJSON function with a new function that recursively looks for date strings in the given format and replaces them with Date objects.
aw, Ok. Tank you!
nice code :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
comment code ? :))