3

Thanks Mythz for providing such an amazing and powerful framework. However, I encountered the DateTime property rendered like this "/Date(1543681261000-0000)/" instead of "2019-03-25T12:50:3000" by using servicestack autoquery. I couldn't find any relevant docs. Please help me.

{
"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

}

mythz
  • 141,670
  • 29
  • 246
  • 390
Steven Li
  • 754
  • 1
  • 8
  • 16

1 Answers1

3

ServiceStack by default uses WCF Dates for JSON, see this answer for different ways to parse WCF Dates in JavaScript.

You can choose to change how dates are serialized in JSON for any JSON Response in ServiceStack by customizing JSON Responses, e.g you can change the JSON returned by the Auto Query Service with:

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

Or use the short-hand alias notation:

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

Alternatively you can tell ServiceStack to always use ISO8601 dates in JSON in your AppHost.Configure() with:

JsConfig.Init(new Config {
    DateHandler = DateHandler.ISO8601
});
mythz
  • 141,670
  • 29
  • 246
  • 390