将日期作为从 Web API 到 angularJS 的 json 响应
Seding date as json response from web api to angularJS
非常简单的问题。
我正在开发一个 angularjs 应用程序,从 asp.net Web API 检索数据。我在表格(模型)中有一个日期字段(此日期),其日期格式如下 -
2015-03-14 12:39:32.470
当我将其作为来自 asp.net 的响应 json 字符串发送时 -
string json = "{'"CreatedAt'": '"" + Model.ThisDate + "'"}";
response.Content = new StringContent(json, Encoding.UTF8, "application/json")
..我在 angularjs 应用程序中得到这样的 -
14-03-2015 12:39:32
当我从 asp.net 将其作为 json 序列化对象发送时 -
JsonConvert.SerializeObject(Model)
..我在 angularjs 应用程序中得到这样的 -
2015-03-14T12:39:32.470
造成这种差异的原因是什么?我希望两者都采用第二种格式,以便排序正确。如何实现这一点?
提前谢谢。
我仍然不确定为什么它会以这种方式转换它们。但是我能够通过在发送响应 json 字符串时指定可排序的日期时间格式来解决此问题,如下所示 -
string json = "{'"CreatedAt'": '"" + Model.ThisDate.ToString("s") + "'"}";
参考这里
相关文章:
- AngularJS JSON not arriving php
- 将Excel/CSV文件中的数据导入angularjs-json对象中
- AngularJS json.parse 在 json 数据的第 1 行第 1 列处意外的数据结尾
- AngularJS JSON漏洞保护是如何工作的
- javascript标记中包含变量的AngularJS JSON数组
- AngularJS - Json to Tree structure
- AngularJS Json 数组的对象
- AngularJS JSON format
- AngularJS - jSON on date 顯示某些 ID
- Angularjs JSON treeview, json format issue
- Blueimp文件上传angularjs json前缀
- AngularJS Json Array
- 用额外的视图逻辑属性丰富angularjs-json数据
- 删除与另一个JSON javascript angularjs-JSON匹配的JSON
- AngularJS Json list
- AngularJS Json Editor
- 有没有办法为AngularJS JSON请求($http/$resource)使用浏览器缓存?
- 如何使用angularjs-json数据设置select 2下拉列表的默认值
- Angularjs json data
- AngularJS/JSON:通过值而不是索引来引用数组成员