惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
S
Schneier on Security
A
Arctic Wolf
L
LangChain Blog
T
Threatpost
GbyAI
GbyAI
V2EX - 技术
V2EX - 技术
Jina AI
Jina AI
U
Unit 42
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
博客园 - 【当耐特】
S
Secure Thoughts
美团技术团队
N
News | PayPal Newsroom
爱范儿
爱范儿
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
S
Security @ Cisco Blogs
V
V2EX
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
腾讯CDC
The Hacker News
The Hacker News
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
Google Online Security Blog
Google Online Security Blog
N
Netflix TechBlog - Medium
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest

博客园 - Tonyyang

【XAF】如何通过前缀或自定义架构将数据库表与内置系统表分开 Power Shell 7 和5.1 批量给pdf添加页码 [XAF] Declare Conditional Appearance Rules in Code DataTableHelper C# 多任务数据同步 【原】 XAF Localization改用百度翻译 C#百度翻译--亲测试可用 SqlQueryDynamic BOM导入 C#上传到FTP Server FREE OFFER - .NET App Security API (Role-based Access Control) 后台管理框架 Model to Model Asp.net MVC 上传文件 Asp.net MVC bootstrap 穿梭框 EXT.NET Combox下拉Grid 转 Refresh Excel Pivot Tables Automatically Using SSIS Script Task SQL Server Integration Services SSIS最佳实践 PowerBI
JSON序列化和反序列化日期时间的处理
Tonyyang · 2021-08-26 · via 博客园 - Tonyyang

可解決

JSON格式不直接支持日期和时间。DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,其中第一个数字(在提供的示例中为 700000)是 GMT 时区中自 1970 年 1 月 1 日午夜以来按正常时间(非夏令时)经过的毫秒数。该数字可以是负数,以表示之前的时间。示例中包括“+0500”的部分可选,它指示该时间属于Local类型,即它在反序列化时应转换为本地时区。如果没有该部分,则会将时间反序列化为Utc。

        [HttpPost]
        public ActionResult EditLoad(Person model)
        { 
            Person obj = personBLL.GetModel(model.FAIGUID);           
            var jsonResult = obj.ToJson();      return Content(jsonResult);      
        }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System.Data;

namespace DAL
{
    public static class JsonTools
    {
        public static object ToJson(this string Json)
        {
            return Json == null ? null : JsonConvert.DeserializeObject(Json);
        }
        public static string ToJson(this object obj)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
            return JsonConvert.SerializeObject(obj, timeConverter);
        }
        public static string ToJson(this object obj, string datetimeformats)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = datetimeformats };
            return JsonConvert.SerializeObject(obj, timeConverter);
        }
        public static T ToObject<T>(this string Json)
        {
            return Json == null ? default(T) : JsonConvert.DeserializeObject<T>(Json);
        }
        public static List<T> ToList<T>(this string Json)
        {
            return Json == null ? null : JsonConvert.DeserializeObject<List<T>>(Json);
        }
        public static DataTable ToTable(this string Json)
        {
            return Json == null ? null : JsonConvert.DeserializeObject<DataTable>(Json);
        }
        public static JObject ToJObject(this string Json)
        {
            return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace("&nbsp;", ""));
        }
    }
}