Newtonsoft.Json的使用
//序列化
JsonConvert.SerializeObject(object value)
//重载方法
JsonConvert.SerializeObject(object value, params JsonConverter[] converters) //反序列化
JsonConvert.DeserializeObject(string value, Type type)
//重载方法JsonConvert.DeserializeObject(string value, Type type, params JsonConverter[] converters)
public class Person
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
}
序列化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json; namespace JSONnet
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Person person = new Person();
person.Name = "GoldenEasy";
person.Age = ;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Response.Write(strSerializeJSON);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json; namespace JSONnet
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Person person = new Person();
person.Name = "GoldenEasy";
person.Age = ;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Person user = (Person)JsonConvert.DeserializeObject(strSerializeJSON, typeof(Person));
Response.Write(user.Name); }
}
}
输出结果为:GoldenEasy
Newtonsoft.Json的使用的更多相关文章
- .Net使用Newtonsoft.Json.dll(JSON.NET)对象序列化成json、反序列化json示例教程
JSON作为一种轻量级的数据交换格式,简单灵活,被很多系统用来数据交互,作为一名.NET开发人员,JSON.NET无疑是最好的序列化框架,支持XML和JSON序列化,高性能,免费开源,支持LINQ查询 ...
- 使用Newtonsoft.Json.dll(JSON.NET)动态解析JSON、.net 的json的序列化与反序列化(一)
在开发中,我非常喜欢动态语言和匿名对象带来的方便,JSON.NET具有动态序列化和反序列化任意JSON内容的能力,不必将它映射到具体的强类型对象,它可以处理不确定的类型(集合.字典.动态对象和匿名对象 ...
- Newtonsoft.Json 自定义 解析协议
在开发web api的时候 遇到一个要把string未赋值默认为null的情况改成默认为空字符串的需求 这种情况就需要自定义json序列话的 解析协议了 Newtonsoft.Json默认的解析协议是 ...
- Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6
未能加载文件或程序集“Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6”或它的某一个 ...
- Newtonsoft.Json 序列化和反序列化 时间格式【转】
1.JSON序列化 string JsonStr= JsonConvert.SerializeObject(Entity); eg: A a=new A(); a.Name="Elain ...
- Newtonsoft.Json 版本冲突解决
在做asp.net MVC 开发时,因为引用的dll 中使用了更高版本的 Newtonsoft.Json ,导致运行时发生错误, 查资料说是因为webApi使用了Newtonsoft.Json 导致了 ...
- JsonHelper developed by using Newtonsoft.Json.NET, Deserialize to <T> object , XmlToJson/JsonToXml, QuoteName by using JToken Path.
namespace TestConsoleApplication { using System; using System.Diagnostics; using System.Threading; u ...
- WP8如何添加Newtonsoft.Json包
WP8开发的时候如何使用Newtonsoft.Json包呢?我在网上包括官网下的DLL文件,添加引用时都给出了这样的提示: 而后在网上找到的解决办法是:使用NuGet程序包来添加. 首先点击工具--& ...
- [.net 面向对象程序设计进阶] (13) 序列化(Serialization)(五) Json 序列化利器 Newtonsoft.Json 及 通用Json类
[.net 面向对象程序设计进阶] (13) 序列化(Serialization)(五) Json 序列化利器 Newtonsoft.Json 及 通用Json类 本节导读: 关于JSON序列化,不能 ...
- Newtonsoft.json中 linq to json 和序列化哪个快?
Newtonsoft.json是最常用的json序列化组件,当然他不是最快的,但是是功能最全的.. using System; using System.Collections.Generic; us ...
随机推荐
- jQuery 复合选择器的几个例子
<!-- 本文例子所引用的jQuery版本为 jQuery-1.8.3.min.js Author:博客园小dee --> 一. 复合选择器对checkbox的相关操作 1 <inp ...
- win7硬盘安装ubuntu双系统——注意项
WIN7 下硬盘安装ubuntu 12.04 博客分类: ubuntu 仅为网络上的资料整理 资料引用:http://www.ctocio.com.cn/35/12325035.shtml htt ...
- PHP 常用函数库和一些实用小技巧
PHP 常用函数库和一些实用小技巧 作者: 字体:[增加 减小] 类型:转载 包括文件读取函式,文件写入函式,静态页面生成函式,目录删除函式等 文件读取函式 //文件读取函式 function ...
- ExtJS笔记2 Class System
For the first time in its history, Ext JS went through a huge refactoring from the ground up with th ...
- 实用Javascript代码片段
清除select下拉选项,添加并选择特点选项 $('#mySelect') .find('option') .remove() .end() .append('<option value=&qu ...
- MZhong's Cover Letter
Application for front-end developer position in Chicago Office Dear HR, I am writing to apply for th ...
- C# vba 操作 Word
添加引用 Microsoft Word *.0 Object Library Microsoft Graph *.0 Object Library 变量说明 Object oMissing = Sy ...
- JMS相关概念
1.相关概念 1)JMS jms即Java消息服务(Java Message Service) 是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送消息 ...
- C、VDD、VSS、 VEE 和VPP的区别
http://www.cnblogs.com/crazybingo/archive/2010/05/14/1735802.html C.VDD.VSS. VEE 和VPP的区别 在电子电路中,常可以看 ...
- 在serviceImpl里使用自身的方法
@Service("tbLeaveRegisterService")@Transactionalpublic class TbLeaveRegisterServiceImpl ex ...