
| home | AJAX (6) || C#.NET (5) || Coldfusion Development (16) || DHTML (14) || Flash Development (19) || jQuery (4) || MSSQL (2) || UNIX (10) |
| 4.24.08 | LitJson Patch To Serialize Hashtable/IDictionary Keys of DateTime Type to JSON |
LitJson is great - lightweight, fast, easy to incorporate, etc. Thanks Leonard Boshell!
I actually found the need to serialize Hashtables to a JSON string that contained Keys that were of the DateTime datatype. LitJson 0.5.0 assumes that the Keys of Hashtable or IDictionary can be cast into a string by default. The DateTime object cannot be CAST into a string, but it can be converted into a string using Convert or ToString().
Case in point - I want to convert:
DateTime currDate = new DateTime();
Hashtable dateTest = new Hashtable();
dateTest.Add(currDate, "random value");
to be able to serialize as (with the default DateTime format):
{"4/24/2008 12:00:00 AM":"random Value"}
Here’s a simple patch to the JsonMapper.cs file:
Download this code: JsonMapper.cs.qwnu.diff
No comments