This is my server-side C# code.
JavaScriptSerializer jsSer = new JavaScriptSerializer();
string strJson = jsSer.Serialize(tableData); \\tableData is List type
string strRawJson = Regex.Replace(strJson, "\\s{2,}", ""); \\ Remove Whitespaces
This is value of strRawJson that I am getting now.
"[{\"RowNumber\":1, ... , "ActivityDate\":\"\\/Date(1378310400000)\\/\",\"ErrMessage\":null}]"
Here is my first question.
I would like to see the value of 'ActivityDate' as this format: '2013-10-24 12:00:00:000'. How can I do?
PLEASE NOTE that I want to do this in C# (NOT JAVASCRIPT), also I don't want to use JSON.NET
Here is my second question
As you can see my third line of code, I used Regex to remove some whitespaces. Is there another possible error when I generate JSON via JavaScriptSerializer?
Thank you very much in advance! :)
[Edit]
I understand that JavascriptSerializer is very limited, but can I still get some help for my 'second' question, please? or Recommend another good serializer?
Do you use MVC.net? If so, you can use this method of the controller:
protected internal JsonResult Json(object data, JsonRequestBehavior behavior)
{
return this.Json(data, (string) null, (Encoding) null, behavior);
}
if you call your action, you will receive the plain json formatted string.
You can use string.Format() to format your date or just do it within js.