-
6 Apr 2008 11:22 AM #1
Date fields in Json response
Date fields in Json response
Hello,
I don't know if this was asked before, I did a search but cannot find a topic about this.
I am using WCF as a Json service, and returning objects as json responses. The objects contain date fields and they appear shown below in the response:
"PublicationStartDate":"\/Date(1207485180000+0300)\/"
I am binding these data to a grid with jsonstore but I cannot succeed in showing the date field on the grid. The column shows empty.
What should I do, can someone guide me please?
Thanks.
-
6 Apr 2008 5:07 PM #2
You want to have a look at http://extjs.com/deploy/dev/docs/?cl...&member=create - you need a convert function that converts your data into a valid Date object.
-
6 Apr 2008 11:25 PM #3
Can't you change the way the server generates the JSON to make it generate
?Code:PublicationStartDate: new Date(2008, 3, 7, 3, 0, 0)
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
7 Apr 2008 2:07 AM #4
That would certainly work for JavaScript as JSON-consumer. But it is not part of the JSON-spec because it will only work in JavaScript.
So: If this WCF thingy only serves your JavaScript frontend then changeing it on the server-side would possible be the quickest way possible.
-
7 Apr 2008 4:09 AM #5
Sure it is possible to change it on the server but I am using automatic serialization, I mean my entities are automatically serialized to json and I don't want to temper with that. I thought it would be easier to handle it on the Ext side.
-
9 Apr 2008 11:38 AM #6
Hello again,
I need a way to intercept data loading process and parse datetime fields manually, removing the "Date" string from the response.
Can someone please guide me?
-
9 Apr 2008 2:36 PM #7
MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
9 Apr 2008 2:42 PM #8
You should think twice before serializing .NET DateTime. In your code you have to take timezones into account on both the client and the server. A much better way is to serialize strings. Then you have complete control of the format and Ext can convert them into dates (almost) automatically. On the server you just use Convert.ToDateTime() and you're good to go.
-
9 Apr 2008 3:55 PM #9
Serializing .Net DateTime is an option, but if I go into that I have to manually serialize all my classes and all the return values of methods that include DateTime. As I said in my second post I am using JSon serialization with DataContracts, I don't write a single line of code to serialize my objects to Json.
I wrote a JsonStore extension that successfully receives Json responses from .Net WCF services and fills comboboxes, grids etc. Only problem seems to be with the DateTime type. Instead of sacrificing all the benefits of automatic serialization, I think extending an Ext type or smth else might be more appropriate for this and future projects.
Record.create is worth looking at.
-
9 Apr 2008 4:06 PM #10
Its not what I meant. You can keep all the nice serialization from WCF but DateTime values is NOT a good idea to serialize. Its a much better approach to mark your public DateTime properties as string (you can still have a private backing field as DateTime, if you need that in your server-side code).
Code:// C# where DateProperty is a DateTime object DateProperty.ToString("yyyy-MM-dd hh:mm:ss");


Reply With Quote