Activate your free membership today | Log-in

Monday, March 3rd, 2008

Json.NET 2.0

Category: .NET, JSON

James Newton-King has quickly released a new version of Json.NET that has a new easier syntax for querying and and creating JSON.

Creating JSON

JAVASCRIPT:
  1.  
  2. JObject o = JObject.FromObject(new
  3. {
  4.   channel = new
  5.   {
  6.     title = "James Newton-King",
  7.     link = "http://james.newtonking.com",
  8.     description = "James Newton-King's blog.",
  9.     item =
  10.         from p in posts
  11.         orderby p.Title
  12.         select new
  13.         {
  14.           title = p.Title,
  15.           description = p.Description,
  16.           link = p.Link,
  17.           category = p.Categories
  18.         }
  19.   }
  20. });
  21.  

Querying JSON

JAVASCRIPT:
  1.  
  2. var categories =
  3.   from c in rss["channel"]["item"].Children()["category"].Values<string>()
  4.   group c by c into g
  5.   orderby g.Count() descending
  6.   select new { Category = g.Key, Count = g.Count() };
  7.  

Check out the project.

Posted by Dion Almaer at 6:11 am
10 Comments

+++--
3.9 rating from 35 votes

10 Comments »

Comments feed TrackBack URI

This looks good. I use Json.NET when I’m not using ASP.NET AJAX and it’s very useful.

@Dion: I think the two code examples are in C# not JavaScript.

Comment by kim3er — March 3, 2008

These cliche web 2.0 logos aren’t funny anymore, just irritating

Comment by Pete B — March 3, 2008

Just a quick correction: the first code block appears to be C# code using LINQ to populate a JSON object (using new fangled C# features like anonymous types and variable instantiation)

Comment by AdamB — March 3, 2008

thank you.

Comment by pessi — March 11, 2008

Thanks. Good article.

Comment by ermenisoykirmi — May 30, 2008

Interesting Article, thanks Armenian Genocide , great information and research.

Comment by ArmenianGenocide — June 8, 2008

Thats great thanks

Comment by Tribulus — September 22, 2008

It’s good. I use Json.NET when I’m not using ASP.NET AJAX. It helps my works a lot.
yuhirocks from quit smoking

Comment by yuhirocks — October 3, 2008

Gucci, on the othergucci handbags hand, presents us with popularity for all gucci diaper bagsthe wrong reasons. In fact, he is currently grounded in his home state of Georgia duefake gucci handbags to legal woes, according to The Associated Press. And unless the bandana-bearer’s albumgucci wallets for men represents a total departure from his current persona, ’s drug references, rampant materialism, brushes with the law and cheap wedding dressesspeak-and-spell rhymes make him a poster child for what ails mainstream rap.

Comment by wuwei — December 16, 2009

It’s Good,Really it is very good.
we web designing company also doing works in .net.
please feel free to contact us at http://www.technowizpvtltd.com

Comment by LIVEPAGES — January 5, 2010

Leave a comment

You must be logged in to post a comment.