C#/ASP.NET JSON date deserialize -


i'm trying deserilize object following code, , i'm wondering proper regex replace json dates. when run following code, regex never gets triggered. i'm using standard json date format inside json string.

{     "uniqueid": "1000000003",          "id": 3,      "modifytimestamp": "/date(1338857699743)/"          }  string json = // see above string p = @"\\/date\((\d+)\+\d+\)\\/"; matchevaluator matchevaluator = new matchevaluator(convertjsondatetodatestring); regex reg = new regex(p); json = reg.replace(json, matchevaluator); javascriptserializer serializer = new javascriptserializer();             student student = serializer.deserialize<student>(json) student;     public static string convertjsondatetodatestring(match m) {         string result = string.empty;         datetime dt = new datetime(1970, 1, 1);         dt = dt.addmilliseconds(long.parse(m.groups[1].value));         dt = dt.tolocaltime();         result = dt.tostring("yyyy-mm-dd hh:mm:ss");         return result;     } 

here working solution:

using system; using system.windows.forms; using system.text.regularexpressions;  namespace resolveoverlapissue {     public partial class form1 : form     {         private static void dosomethingelse<t>(ref t id)         {             int = 00;         }          public form1()         {             initializecomponent();              string json = "{" +                           "uniqueid: 1000000003," +                           "id: 3," +                           "modifytimestamp: /date(1338857699743)/" +                           "}";              matchevaluator matchevaluator = convertjsondatetodatestring;             var reg = new regex(@".date\(\d+\)\/.");             json = reg.replace(json, matchevaluator);          }          public static string convertjsondatetodatestring(match m)         {             var dt = new datetime(1970, 1, 1);             dt = dt.addmilliseconds(long.parse(m.groups[1].value));             dt = dt.tolocaltime();             var result = dt.tostring("yyyy-mm-dd hh:mm:ss");             return result;         }     } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -