Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good .NET libraries for working with JSON data? [closed]

I am currently trying out Json.NET, and it seems to work well.

Any other good JSON libraries for .NET?

like image 280
TWA Avatar asked Jun 12 '09 12:06

TWA


People also ask

Does .NET support JSON?

Text. Json namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON).

What is serialize in JSON?

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object).


3 Answers

There is the JavascriptSerialiser which is used by asp.net mvc and asp.net ajax. Also there is the DataContractJsonSerialiser used by WCF. The only problem I have encountered with the JavascriptSerialiser is that it uses funny way to serialise dates, which I do not think will parse into a javascript date. But this is easyly solved by this snippet

    public double MilliTimeStamp()
    {
        DateTime d1 = new DateTime(1970, 1, 1);
        DateTime d2 = DateTime.UtcNow;
        TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);

        return ts.TotalMilliseconds;
    }
like image 113
superlogical Avatar answered Oct 31 '22 11:10

superlogical


The class JavaScriptSerializer from the System.Web.Script.Serialization namespace provides good JSON serialization/deserialization support.

like image 20
Ronald Wildenberg Avatar answered Oct 31 '22 11:10

Ronald Wildenberg


Jayrock works well and transparently turns your objects to and from JSON objects providing they have a public constructor. It also creates the script for you so you can just call your web service like a Javascript class.

Example:

public class Person
{
  public string Name { get;set;}
  public int Age { get;set; }

  public Person() { }
}

public class MyService : JsonRpcHandler
{
   [JsonRpcMethod("getBob")]
   public Person GetBob()
   {
       return new Person() { Name="Bob",Age=20};
   }
}

And the Javascript:

var service = new MyService();
var result = service.getBob();
alert(result.name); // JSON objects are camel-cased.
like image 1
Chris S Avatar answered Oct 31 '22 11:10

Chris S