https://github.com/mganss/microjson
A small two-file JSON serializer in C# that works on MonoDroid/MonoTouch
https://github.com/mganss/microjson
Last synced: 6 months ago
JSON representation
A small two-file JSON serializer in C# that works on MonoDroid/MonoTouch
- Host: GitHub
- URL: https://github.com/mganss/microjson
- Owner: mganss
- Created: 2011-12-14T16:53:47.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2019-06-25T15:43:03.000Z (over 6 years ago)
- Last Synced: 2024-04-28T20:06:04.358Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 205 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
MicroJson
=========[](https://www.nuget.org/packages/MicroJson)
[](https://ci.appveyor.com/project/mganss/microjson/branch/master)
[](https://coveralls.io/github/mganss/MicroJson?branch=master)MicroJson is a small library for serializing/deserializing [JSON](http://www.json.org/) strings from strongly
typed CLR objects (POCOs). It is basically a replacement for the [JavaScriptSerializer](http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx)
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](http://json.codeplex.com/).MicroJson consists of two source files you can just drop into your project. It has been tested in the following environments:
- .NET 4.0
- [Mono](http://www.mono-project.com/Main_Page) 2.10
- [MonoTouch](http://www.xamarin.com) ([Touch.Unit](https://github.com/spouliot/Touch.Unit) tests included)
- [Mono for Android](http://www.xamarin.com) ([Andr.Unit](https://github.com/spouliot/Andr.Unit) tests included)Usage
-----public class Test
{
public string S { get; set; }
public int I { get; set; }
public List L;
}var json = @"{
""S"": ""Hello, world."",
""I"": 4711,
""L"": [1, 2, 3]
}";
var t = new JsonSerializer().Deserialize(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` and JSON objects into `Dictionary`. 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](http://en.wikipedia.org/wiki/MIT_License)
Used at
---------[UpdateStar](http://www.updatestar.com/)