大佬教程收集整理的这篇文章主要介绍了Json.NET - Documentation Creating JSON,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
SetTing values and creaTing objects and arrays one at a time gives you @R_977_10586@l control but it is more verbose than other options.
CreaTing JSON Copy imageCopy
1JArray array = new JArray();
2JValue text = new JValue("Manual text");
3JValue date = new JValue(new datetiR_489_11845@e(2000,5,23));
4
5array.Add(text);
6array.Add(datE);
7
8String json = array.ToString();
9// [
10// "Manual text",
11// "2000-05-23T00:00:00"
12// ]
CreaTing JSON with LINQ
Declaratively creaTing JSON objects using LINQ is a fast way to create JSON from collections of values.
CreaTing JSON Declaratively Copy imageCopy
1List<Post> posts = GetPosts();
2
4 new JObject(
5 new JProperty("chAnnel",
6 new JObject(
7 new JProperty("title","James Newton-King"),
8 new JProperty("link","http://james.newtonking.com"),
9 new JProperty("description","James Newton-King's blog."),
10 new JProperty("item",
11 new JArray(
12 from p in posts
13 orderby p.title
15 new JProperty("title",p.titlE),
16 new JProperty("description",p.Description),
17 new JProperty("link",p.Link),
18 new JProperty("category",
19 new JArray(
20 from c in p.Categories
21 SELEct new JValue(C)))))))));
22
23Console.WriteLine(RSS.ToString());
24
25//{
27// "title": "James Newton-King",
28// "link": "http://james.newtonking.com",
29// "description": "James Newton-King's blog.",
30// "item": [
31// {
32// "title": "Json.NET 1.3 + New license + Now on CodePlex",
33// "description": "Annoucing the release of Json.NET 1.3,the MIT license and being available on CodePlex",
34// "link": "http://james.newtonking.com/projects/json-net.aspx",
35//
以上是大佬教程为你收集整理的Json.NET - Documentation Creating JSON全部内容,希望文章能够帮你解决Json.NET - Documentation Creating JSON所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。