win8 ghost,建湖新闻,顺藤摸瓜的近义词
执行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(0); }); } }
打开postman再次运行,查看结果
前段js再次取得该字符串时间,就可以正确的识别时间类型字段了。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论