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

推荐订阅源

S
Security @ Cisco Blogs
H
Hacker News: Front Page
P
Privacy International News Feed
N
News and Events Feed by Topic
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
K
Kaspersky official blog
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
Jina AI
Jina AI
P
Proofpoint News Feed
AI
AI
雷峰网
雷峰网
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 叶小钗
Webroot Blog
Webroot Blog
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
罗磊的独立博客
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
月光博客
月光博客
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Securelist
W
WeLiveSecurity
T
Troy Hunt's Blog
A
Arctic Wolf
博客园 - 司徒正美

博客园 - dail

IE浏览器在虚拟机中无法正常显示字符 jQuery在updatepanel中使用造成内存泄露 在使用jQuery的时候不小心的内存泄漏 jQuery 1.7的隐藏改动 在javascript中实现类似asp.net webcontrol中的render的方法 jQuery 1.6的变化 jQuery ui effects - dail jQuery ui 1.8.6 position 的一个bug 一个progressbar widget jQuery编写widget的一些窍门 jquery animate动画的特殊用法。 一个简单的widget Jquery ui widget中的_create(),_init(),destroy() Jquery ui widget开发 Jquery ui css framework jquery animate EXTJS学习(二)Message EXTJS学习(一) jquery+linq制作博客(二)
Json.net简单用法
dail · 2008-10-13 · via 博客园 - dail

Json.Net这个程序集可以帮我们很好的实现对象到json的转换。对于了解javascript的人来说json并不会很陌生,在现在很多的js框架中,json也用的很多。在ext中很多数据和设置都是采用json格式的。在数据的读取,可以直接从后端传递json对象。比如说ext的grid控件,其数据来源就可以是json,当然也可以是xml但是,相比json来数,数据较为简单,并且传输的数据量也比xml小。在做这些应用的时候,我们采用json.net就可以很方便的将.net中的对象转换成json字符串。然后传递到前段供调用。

关于json更多的内容可以参考http://www.json.org/json-zh.html
josn.net下载:Json.NET Download

以下就json常用的方法给大家做一个简单的例子:

JavaScriptConvert.SerializeObject:将对象转换为josn字符串

 Product product = new Product();

product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string json = JavaScriptConvert.SerializeObject(product);

Newtonsoft.Json.JavaScriptConvert.DeserializeObject:根据json字符串反序列化得到对象。

Product deserializedProduct = (Product)JavaScriptConvert.DeserializeObject(output, typeof(Product));

其中的output就是一个json字符串,而product是要反序列化的类对象

通过这两个常用的方法,就可以很方便的从json字符串得到对象和从对象得到json字符串。