Wrox Programmer Forums
BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6
This is the forum to discuss the Wrox book Professional Ajax, 2nd Edition by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780470109496
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 11th, 2009, 10:33 AM
Registered User
Join Date: Mar 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default C# and JSON

I decided to buy a copy of Professional Ajax because it focuses on a few technologies and techniques that I want to learn. I was also impressed with nzakas and jminatel's professionalism while facing unfounded criticism.

jminatel: I apologize for the statements in my post that required editing. I will make note of your rules and do my best to abide by them.

My question doesn't really pertain to the subject matter in the book, but rather recommendations made in it. I am learning C#, and in chapter 8 you recommend the JSON.NET library found at http://www.newtonsoft.com/products/json. Has that recommendation changed in the past three years? Are there better alternatives to JSON.NET?
Old March 11th, 2009, 01:10 PM
jmcpeak's Avatar
Wrox Author
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts

Howdy, Throp.

We used the Json.NET library throughout the book, so if want to follow the code I recommend the version of Json.NET supplied in the code download. The DLL is in the bin folders wherever we used it.

If your inquiry is for your own projects, I’ll disclaim this post by saying I haven’t used many JSON libraries for .NET. We used one library (Nii.JSON.dll) for the first edition of Professional Ajax, and we switched to Json.NET for the second edition. The only other JSON serializer/deserializer I’ve used is what Microsoft added to the CLI for .NET 3.0. My personal recommendations are as follows:

.NET 1.1 – Nii.JSON found at http://www.json.org/cs.zip

.NET 2.0 – Eearly versions of Json.NET http://www.codeplex.com/json

.NET 3.5 (what I’ll focus on since it’s the latest version of .NET) – Either Json.NET or the classes in the System.Runtime.Serialization.Json namespace. I prefer Json.NET. It’s nice when Microsoft adds support for any technology to .NET, but their additions are typically and unfortunately basic. Anything more advanced requires you to either find a third party library or roll your own library. I find more value in Json.NET than I do in the System.Runtime.Serialization.Json namespace. It’s also worth mentioning that I use LINQ like it’s going out of style, and I find the LINQ to JSON features very handy.

Features aside, serializing objects and deserializing JSON text is much simpler with Json.NET.
// Json.NET Serializing
string json = JavaScriptConvert.SerializeObject(myObj);

// Json.NET Deserializing
MyObj deserializedObj = JavaScriptConvert.DeserializeObject<MyObj>(json);

// System.Runtime.Serialization.Json.DataContractJsonSerializer Serializing
DataContractJsonSerializer serializer = new DataContractJsonSerializer(myObj.GetType());
using (MemoryStream ms = new MemoryStream())
    serializer.WriteObject(ms, myObj);
    string json = Encoding.Default.GetString(ms.ToArray());

// System.Runtime.Serialization.Json.DataContractJsonSerializer Deserializing
MyObj myObj = new MyObj();
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(myObj.GetType());
    myObj = serializer.ReadObject(ms) as MyObj;
So to answer your question, it’s ultimately up to you. It’s always good to know how to use the tools Microsoft provides you; use it if their implementation is sufficient for your needs. If it is, you can always write a helper class leveraging the power of generics to make serializing and deserializing less painful and more like Json.NET’s API.

I hope this helps you determine what route you want to take.

Last edited by jmcpeak; March 11th, 2009 at 01:13 PM.. Reason: Added link to Json.NET at CodePlex
The Following User Says Thank You to jmcpeak For This Useful Post:
throp (March 12th, 2009)
Old March 12th, 2009, 10:51 AM
Registered User
Join Date: Mar 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts

Thanks for the reply, jmcpeak. I think I will stick with JSON.NET. It is nice to know that the .NET Framework has JSON functionality.

Last edited by throp; March 12th, 2009 at 10:53 AM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
JSON-PHP v. PHP-JSON bcrocks BOOK: Professional Ajax ISBN: 978-0-471-77778-6 2 August 17th, 2011 07:52 AM
C# JSON Library radhakrishnane BOOK: Professional Ajax ISBN: 978-0-471-77778-6 2 January 21st, 2009 09:36 AM
C# object to/from JSON possible?!? quantass BOOK: Beginning Ajax with ASP.NET 1 January 21st, 2009 09:32 AM
JSON and ScriptService balesh.mind ASP.NET 3.5 Basics 0 December 4th, 2008 08:14 AM
JSON problem with accentuation jlamas Ajax 0 September 8th, 2006 07:25 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.