Monday, March 3rd, 2008

Json.NET 2.0

Category: .NET, JSON

<p>

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

Querying JSON

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

Check out the project.

Related Content:

Posted by Dion Almaer at 6:11 am
6 Comments

+++--
3.9 rating from 36 votes

6 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

Thats great thanks

Comment by Tribulus — September 22, 2008

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.