3

感谢 Mythz 提供了如此惊人而强大的框架。但是,我遇到了使用 servicestack 自动查询呈现像这样的“/Date(1543681261000-0000)/”而不是“2019-03-25T12:50:3000”的 DateTime 属性。我找不到任何相关文档。请帮我。

{
"customer": [
    {
        "transaction_total": 0,
        "text": "0067 83228780",
        "transaction_time": 0,
        "action": 0,
        "point_collection_on_registration": false,
        "id": 71,
        "push_notification_id": "null",
        "name": "0067",
        "ic": "27668",
        "type": 0,
        "phone_no": "83228780",
        "point": 5132,
        "balance": 1621.3,
        "issue_date": "/Date(1543681261000-0000)/",
        "is_subscribed": true,
        "is_expiry": false,
        "lang_preferred": "cn",
        "is_delete": false
    }
],
"count_all": 120

}

4

1 回答 1

3

ServiceStack 默认使用 JSON 的 WCF 日期,请参阅此答案以了解在 JavaScript 中解析 WCF 日期的不同方法

您可以通过自定义 JSON Responses来选择更改 ServiceStack 中任何 JSON 响应的日期在 JSON 中的序列化方式,例如,您可以使用以下命令更改自动查询服务返回的 JSON:

  • ?jsconfig=DateHandler:ISO8601
  • ?jsconfig=DateHandler:ISO8601DateOnly
  • ?jsconfig=DateHandler:ISO8601DateTime

或者使用简写的别名符号:

  • ?jsconfig=dh:iso8601
  • ?jsconfig=dh:iso8601do
  • ?jsconfig=dh:iso8601dt

或者,您可以告诉 ServiceStack 在您的AppHost.Configure()with 中始终使用 JSON 格式的 ISO8601 日期:

JsConfig.Init(new Config {
    DateHandler = DateHandler.ISO8601
});
于 2019-03-26T06:51:32.483 回答