执行dotnet-new selfhost sstest 创建项目,然后打开解决方案

修改ssTest.ServiceModel中的Hello.cs,在HellopResponse中添加时间属性,然后修改MyServices中的代码

运行程序,打开Postman查看返回结果

可以看到Json中date属性返回的是  "date": "/Date(1555810731732+0800)/",直接导致前段js无法识别该字段,该如何解决?

在Startup中加入以下代码,任何时间都转换为ISO8601字符串

    public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
JsConfig<DateTime>.SerializeFn = time => new DateTime(time.Ticks, DateTimeKind.Local).ToString("o");
JsConfig<DateTime?>.SerializeFn =
time => time != null ? new DateTime(time.Value.Ticks, DateTimeKind.Local).ToString("o") : null;
JsConfig.DateHandler = DateHandler.ISO8601; app.UseServiceStack(new AppHost()); app.Run(context =>
{
context.Response.Redirect("/metadata");
return Task.FromResult();
});
}
}

打开Postman再次运行,查看结果

前段js再次取得该字符串时间,就可以正确的识别时间类型字段了。

ServiceStack DateTime数据类型转Json出现的困扰的更多相关文章

  1. Python全栈--7模块--random os sys time datetime hashlib pickle json requests xml

    模块分为三种: 自定义模块 内置模块 开源模块 一.安装第三方模块 # python 安装第三方模块 # 加入环境变量 : 右键计算机---属性---高级设置---环境变量---path--分号+py ...

  2. 11月13日上午ajax返回数据类型为JSON数据的处理

    ajax返回数据类型为JSON数据的处理 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  3. sql server2000中使用convert来取得datetime数据类型样式(全)

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...

  4. Asp.Net WebAPI配置接口返回数据类型为Json格式

    Asp.Net WebAPI配置接口返回数据类型为Json格式   一.默认情况下WebApi 对于没有指定请求数据类型类型的请求,返回数据类型为Xml格式 例如:从浏览器直接输入地址,或者默认的XM ...

  5. Pythoy 数据类型序列化——json&pickle 模块

    Pythoy 数据类型序列化--json&pickle 模块 TOC 什么是序列化/反序列化 pickle 模块 json 模块 对比json和pickle json.tool 命令行接口 什 ...

  6. python datetime.datetime is not JSON serializable

    1.主要是python  list转换成json时对时间报错:datetime.datetime(2014, 5, 23, 9, 33, 3) is not JSON serializable. 2. ...

  7. datetime is not json serializable

    python, datetime is not json serializable import datetime def json_serial(obj): """JS ...

  8. DateTime数据类型保存问题(DateTime2)

    DateTime And DateTime2 问题: 从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值 原因: EF中model存在datetime类型的字段, ...

  9. SQL Server datetime数据类型设计、优化误区

    一.场景 在SQL Server 2005中,有一个表TestDatetime,其中Dates这个字段的数据类型是datetime,如果你看到表的记录如下图所示,你最先想到的是什么呢? (图1:数据列 ...

随机推荐

  1. nginx指令中的优化(配置文件)

    nginx指令中的优化(配置文件)worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_cpu_affinity 00000001 0000 ...

  2. Continuous Subarray Sum LT523

    Given a list of non-negative numbers and a target integer k, write a function to check if the array ...

  3. IOS初级:UIAlertController

    - (IBAction)signOutAction:(id)sender { //初始化,StyleActionSheet是对话框的样式 UIAlertController *alert = [UIA ...

  4. JDBC连接MySql,配置url报错

    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one ...

  5. dfs序理解-hdu3887

    dfs序就是相当于把树转化成了一个区间,在区间上进行操作. void dfs(int u, int fa) { l[u]=++key; ; i=e[i].next) { int v=e[i].v; i ...

  6. python文件打包

    python文件打包 先安装 pip3 install --upgrade pyinstaller 进入到文件的当前目录 ,在命令行中输入: pyinstaller -F -w[文件名].py 其中- ...

  7. rails 表单中默认值

    在表单中加入默认提示值,如(email@email.com): <div class="field"> <%= form.label :email,"E ...

  8. 2018.12.14 codeforces 932E. Team Work(组合数学)

    传送门 组合数学套路题. 要求ans=∑i=0nCni∗ik,n≤1e9,k≤5000ans=\sum_{i=0}^n C_n^i*i^k,n\le 1e9,k\le 5000ans=∑i=0n​Cn ...

  9. hdu-1033(格式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1033 参考文章:https://blog.csdn.net/curson_/article/detai ...

  10. react添加方法的两种形式

    1.使用bind <button onClick={this.test.bind(this)}>确定</button> 2.使用箭头函数 <button onClick= ...