josephvusich / MicroJson

A small two-file JSON serializer in C# that works on MonoDroid/MonoTouch. This fork has an assortment of bugfixes, and is optimized for use as a Shared Project from a Space Engineers MDK Project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MicroJson

Version Build status Coverage Status

MicroJson is a small library for serializing/deserializing JSON strings from strongly typed CLR objects (POCOs). It is basically a replacement for the JavaScriptSerializer class for situations where you cannot or do not want to use that class. Its aim is neither to be fast nor feature-rich but rather small and compatible with most environments. If you are looking for a more fully featured JSON serializer, you should probably take a look at JSON.Net.

MicroJson consists of two source files you can just drop into your project. It has been tested in the following environments:

Usage

public class Test
{
    public string S { get; set; }
    public int I { get; set; }
    public List<int> L;
}

var json = @"{
    ""S"": ""Hello, world."",
    ""I"": 4711,
    ""L"": [1, 2, 3]
}";

var t = new JsonSerializer().Deserialize<Test>(json);

Assert.That(t.S, Is.EqualTo("Hello, world."));
Assert.That(4711, Is.EqualTo(t.I));
Assert.That(new[] { 1, 2, 3 }, Is.EquivalentTo(t.L));

var j = new JsonSerializer().Serialize(t);

Assert.That(j, Is.EqualTo(@"{""I"":4711,""L"":[1,2,3],""S"":""Hello, world.""}"));

Notes

Deserialization is a two step process. First, JSON text is deserialized into generic CLR objects, i.e. JSON arrays into List<object> and JSON objects into Dictionary<object>. If you only need this, then you can just include JsonParser.cs.

Type information can be preserved when de/serializing by setting the UseTypeInfo property to true on the JsonSerializer object. This will emit the class name of a serialized object as an additional property (can be configured through the property TypeInfoPropertyName, default is @type) for classes which are derived and/or implement an interface.

License

MIT X11

Used at

UpdateStar

About

A small two-file JSON serializer in C# that works on MonoDroid/MonoTouch. This fork has an assortment of bugfixes, and is optimized for use as a Shared Project from a Space Engineers MDK Project.


Languages

Language:C# 100.0%