Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391336

Working and tested JSon serializers for .NET 4?

Entire question is in the title: Are there any working, and tested, JSon serializer implementations for .NET 4?

I tried Json.NET on codeplex, but it is neither updated for .NET 4.0, nor does it handle culture differences (like comma/dot in floating point values).

Are there any that works?

Upvotes: 0

Views: 172

Answers (2)

James Black
James Black

Reputation: 41858

This is what I use for my WCF4 REST service, and it works fine, so the DataContractJsonSerializer should work for you.

    public static string SerializeToJSON<T>(T obj)
    {
        string sRet = "";
        var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
        using (var memStream = new System.IO.MemoryStream())
        {
            serializer.WriteObject(memStream, obj);
            byte[] blob = memStream.ToArray();
            var encoding = new System.Text.UTF7Encoding();
            sRet = encoding.GetString(blob);
        }
        return sRet;
    }

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

Aren't the ones built-in the framework working in your scenario (JavaScriptSerializer and DataContractJsonSerializer)? Those are guaranteed to be working and tested.

Upvotes: 3

Related Questions