I wrote a JSONHelper extension
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization; namespace CapMon.Utilities
{
public static class JsonHelper
{
private static JsonSerializerSettings _jsonSettings; static JsonHelper()
{
IsoDateTimeConverter datetimeConverter = new IsoDateTimeConverter();
datetimeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; _jsonSettings = new JsonSerializerSettings();
_jsonSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
_jsonSettings.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
_jsonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
_jsonSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
_jsonSettings.Converters.Add(datetimeConverter);
} public static string ToJson(this object obj)
{
try
{
if (null == obj)
return null; return JsonConvert.SerializeObject(obj, Formatting.None, _jsonSettings);
}
catch (Exception ex)
{
Logging.LogExeption(ex); return null;
}
} public static T FromJson<T>(this string json)
{
try
{
return JsonConvert.DeserializeObject<T>(json, _jsonSettings);
}
catch (Exception ex)
{
Logging.LogExeption(ex); return default(T);
}
}
}
}
I wrote a JSONHelper extension的更多相关文章
- 动态linq表达式新方法,Dynamic LINQ Extension Method
Remember those old posts on Dynamic LINQ? You are probably aware that Microsoft has made its impleme ...
- [PHP] Compile an extension on Windows
https://wiki.php.net/internals/windows/stepbystepbuildhttp://blog.benoitblanchon.fr/build-php-extens ...
- Asp.Net Core 轻松学-一行代码搞定文件上传 JSONHelper
Asp.Net Core 轻松学-一行代码搞定文件上传 前言 在 Web 应用程序开发过程中,总是无法避免涉及到文件上传,这次我们来聊一聊怎么去实现一个简单方便可复用文件上传功能:通过创建 ...
- 【转】Setting up SDL Extension Libraries on Visual Studio 2010 Ultimate
FROM:http://lazyfoo.net/tutorials/SDL/06_extension_libraries_and_loading_other_image_formats/windows ...
- Windbg Extension NetExt 使用指南 【2】 ---- NetExt 的基本命令介绍
摘要 : 本章节介绍NetExt常用的命令. 并且对SOS进行一些对比. NetExt的帮助 要想玩好NetExt, 入门就得看帮助. 看NetExt的帮助可以调用!whelp 命令. 这样hi列举出 ...
- Windbg Extension NetExt 使用指南 【1】 ---- NetExt 介绍
摘要 : 在使用WINDBG做debugging的时候,需要一个好的工具帮助进行数据分析. 最常见的extension包括SOS, PSSCOR. NetExt则是另外一种提供了丰富命令功能的deb ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JSON扩展类——JsonHelper
1.引用Newtonsoft.Json库(JSON.NET). 2.复制粘贴JsonHelper吧. 源代码: using System; using System.Collections.Gener ...
- PHPmailer关于Extension missing: openssl报错的解决
最近在写一个网页的时候,需要用到PHPmailer来发送邮件,按照官网上给出的demo写出一个例子,却报错Extension missing: openssl 最后发现需要修改php.ini中的配置: ...
随机推荐
- 搭建cvs服务器
http://zhangjunhd.blog.51cto.com/113473/78595 http://www.cnblogs.com/lee/archive/2008/10/22/1317226. ...
- Ubuntu下使用Git_2
接着上一篇的写,这里练习一下git clone 指令 指令格式 $ git clone <repository> <directory> <respository> ...
- 序列化---fastjson使用
该文章主要介绍com.alibaba.fastjson的使用. 首先创建maven工程,导入fastjson.挑个热度高的版本就好了. 首先考虑下,我们通常什么时候会使用序列化和反序列化: 1.将ja ...
- python xlrd处理表格常用方法
1.导入模块import xlrd2.打开Excel文件读取数据data = xlrd.open_workbook('excelFile.xls')3.使用技巧获取一个工作表 table = data ...
- python 调用RESTFul接口
本周需要将爬虫爬下来的数据入库,因为之前已经写好PHP的接口的,可以直接通过python调用PHP接口来实现,所以把方法总结一下. //python编码问题,因为好久用,所以很容易出现 # -*- c ...
- 用vs调试项目页面无样式
ASP.NET Development Server 上的文件授权 在文件系统网站中,静态文件(例如图像和样式表)遵守 ASP.NET 授权.例如,如果禁用了对静态文件的匿名访问,匿名用户则不能使用文 ...
- lintcode-103-带环链表 II
带环链表 II 给定一个链表,如果链表中存在环,则返回到链表中环的起始节点的值,如果没有环,返回null. 样例 给出 -21->10->4->5, tail connects to ...
- ArcGIS API for javascript中搜索框的使用问题
我们在开发中常常需要用搜索框去搜索地图上的某个数据,然后在地图上显示出来.这个时候我们要用到esri.dijit.Search().在设置里面的sources的时候,需要注意一点:必须要使用在线的fe ...
- sqlite sql语句关键字GROUP BY的理解
第一遍看GROUP BY的介绍时,没看懂. SQLite 的 GROUP BY 子句用于与 SELECT 语句一起使用,来对相同的数据进行分组.在 SELECT 语句中,GROUP BY 子句放在 W ...
- SSH整合需要的jar包
[struts相关jar] commons-fileupload-1.2.2.jar commons-io-2.0.1.jar commons-lang3-3.1.jar freemarker-2.3 ...