How to return custom datetime format in WCF REST Service?

As we know,we can define a method called by client in WCF REST Service like this:

[WebInvoke(UriTemplate = "ValidateLogin", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public ValidationClass ValidateLogin(RequestObject obj){...}

The object ValidationClass contains a DateTime type property.

It will return the result like below to the client.

{
    "isValid":true,
    "returnMessage":"string",
    "tokenID":"string",
    "zones":[{
        "DayOfWeek":"string",
        "END_TIME":"/Date(928120800000+0800)/",
        "ID":2147483647,
        "PHONE_NO":"string",
        "START_TIME":"/Date(928120800000+0800)/"
    }],
    "zonesOpen":[{
        "ID":2147483647,
        "POSITION_END_TIME":"/Date(928120800000+0800)/",
        "POSITION_START_TIME":"/Date(928120800000+0800)/",
        "POSITION_WEEK":2147483647,
        "TT_ID":"string"
    }]
}

Client(Android developer) have to convert the DateTime value to Standard Time format like 'yyyy-MM-dd hh:mm:ss' , they complain it is not friendly to them.

So I try to resolve this, in my opinion, there is an interface(or abstract class) to serialize object to JSON string, I need to inherit it and override the methods, add elements to configuration file to tell System to use my serialization class instead of itself, but it is no way so far.

Does my idea work?

链接地址: http://www.djcxy.com/p/8144.html

上一篇: 将时间戳转换为日期,然后转换回时间戳

下一篇: 如何在WCF REST服务中返回自定义日期时间格式?