c# 在.NET使用Newtonsoft.Json转换,读取,写入json
转自:http://blog.sina.com.cn/s/blog_70686f3a0101kemg.html
JsonConvert.DeserializeObject(string value, Type type),反序列化,它有个重载方法JsonConvert.DeserializeObject(string value, Type type, params JsonConverter[]
converters)
这两个方法可以实现基本的序列化和反序列化要求,请看下面的例子:
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
{
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 = 25;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Response.Write(strSerializeJSON);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
{
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 = 25;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Person user = (Person)JsonConvert.DeserializeObject(strSerializeJSON, typeof(Person));
Response.Write(user.Name);
}
}
c# 在.NET使用Newtonsoft.Json转换,读取,写入json的更多相关文章
- 在.NET使用Newtonsoft.Json转换,读取,写入json
首先,大家要明白什么是json,了解更多关于json方面资料大家可以点击https://www.ibm.com/developerworks/cn/web/wa-lo-json/ ,我在这里简单介绍下 ...
- Asp.Net中使用Newtonsoft.Json转换,读取,写入
using Newtonsoft.Json;using Newtonsoft.Json.Converters; //把Json字符串反序列化为对象目标对象 = JsonConvert.Deserial ...
- 在.NET中使用Newtonsoft.Json转换,读取,写入的方法介绍
全局引用 using Newtonsoft.Json; using Newtonsoft.Json.Converters; //把Json字符串反序列化为对象 目标对象 = JavaScriptCon ...
- 19.JAVA-从文件中解析json、并写入Json文件(详解)
1.json介绍 json与xml相比, 对数据的描述性比XML较差,但是数据体积小,传递速度更快. json数据的书写格式是"名称:值对",比如: "Name" ...
- C++简单使用Jsoncpp来读取写入json文件
一.源码编译 C++操作json字符串最好的库应该就是jsoncpp了,开源并且跨平台.它可以从这里下载. 下载后将其解压到任意目录,它默认提供VS2003和VS2010的工程文件,使用VS2010可 ...
- python 数据写入json文件时中文显示Unicode编码问题
一.问题描述 import json dir = { '春晓':'asfffa', '春眠不觉晓' : '处处闻啼鸟', '夜来风雨声' : 56789, 'asdga':'asdasda' } fp ...
- Newtonsoft.Json 转换DateTime类型为字符串时,串内部会有一个T。解决方案
使用Newtonsoft.Json 转换DateTime类型时,若使用标准转换,则字符串内会有一个T(虽然再转换成DateTime没有问题). 若要转换成DateTime没有T,可以加上特性: pub ...
- Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty
原文:Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty public class NullToEmptyStringResolver : De ...
- [转] JSON转换
转载自:http://www.360doc.com/content/12/0413/14/9529755_203286509.shtml# JSON简介 JSON(JavaScript Object ...
随机推荐
- 查看当前Jquery版本
<script type="text/javascript"> $(document).ready(function(){ alert(jQuery.fn.jquery ...
- Echars使用
声明一个Echars: var myChart = echarts.init(document.getElementById(Id)); 给Echars添加参数: var option = { 参数 ...
- angular6 safe url pipe
safe-url.pipe.ts import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from ' ...
- C# Winform 仪表盘
winform 仪表盘相关下载链接://download.csdn.net/download/floweroflvoe/10432601?utm_source=bbsseo 控件首次拖拽上来是这样的: ...
- React 的组件与 this.props对象
1.组件 React 允许将代码封装成组件,然后像插入普通 HTML 标签一样,在网页中插入这个组件.React.createClass 的方法就是用于生成一个组件类. 2.this.props对象 ...
- CQRS粗浅理解
CQRS(命令查询责任分离)是一种奇特的模式,表示解耦系统的输入和输出. 通常情况下,输入端将数据写到数据库,输出端从数据库查询.与读写锁的场景类似,写的过程中不能读.正常情况下没有问题,但是在大规模 ...
- raid卡的结构示意图
raid卡的结构示意图,取自<大话存储>第124页 ROM:一般用FLash芯片做ROM,存放着初始化RAID卡必须的代码以及实现RAID功能所需的代码; XOR芯片:专门用来做RAID ...
- Python运行时的常见错误
1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加冒号(:)(导致 “SyntaxError :invalid syntax”) 2)使用 ...
- calc属性
在单个元素,或者多个可重复css元素使用, 如width: calc(100% - 100px);此元素宽度等于父级宽度下减100像素
- 初遇sass的两个小问题
关于sass大家都知道是一种css的开发工具,原本的css没有变量 参数一类的东西,所以比较死 效率较慢. sass就是在css里面加入了一些编程的元素如变量等,让css能够更灵活,提高效率. 刚接触 ...