c# - Configure JSON serialization for ASP.NET web service -


i have .asmx web service communicates using json. return objects asp.net magically serializes json.

the issue dates serialized this:

"mydate": "\/date(1388332525)\/" 

and need them serialized in iso8601 format, this:

"mydate":"\/date(2012-09-19t03:27:14)\/" 

using asp.net's web api not option @ point, question this: there way configure default json serializer asp.net web services in such way return iso8601 dates?

in asmx files, set return type void , this...

mycustomclass myobj=mycustomclass.load(); string myjson=jsonconvert.serializeobject(myobj); httpcontext.current.response.contenttype="application/json"; httpcontext.current.response.write(myjson); 

i have finer grained control on output. if you're running json.net 4.5, should have iso 8601 date format default. let's you're running older version. below should (make sure set return type void function in asmx).

jsonserializersettings isodateformatsettings = new jsonserializersettings(){ dateformathandling = dateformathandling.isodateformat }; mycustomclass myobj=mycustomclass.load(); string myjson=jsonconvert.serializeobject(myobj, isodateformatsettings); httpcontext.current.response.contenttype="application/json"; httpcontext.current.response.write(myjson); 

this based on json.net documentation.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -