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

+++--
3.8 rating from 32 votes

8 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

Leave a comment

You must be logged in to post a comment.