| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A really simple C# JSON parser in ~350 lines
class Foo
{
public int Value;
}
"{\"Value\":10}".FromJson<Foo>()var test = "{\"Value\":10}".FromJson<object>();
int number = ((Dictionary<string,object>)test)["Value"];Limitations:
This example will write a list of ints to a File and read it back again:
using System;
using System.IO;
using System.Collections.Generic;
using TinyJson;
public static class JsonTest
{
public static void Main(string[] args)
{
//Write a file
List<int> values = new List<int> { 1, 2, 3, 4, 5, 6 };
string json = values.ToJson();
File.WriteAllText("test.json", json);
//Read it back
string fileJson = File.ReadAllText("test.json");
List<int> fileValues = fileJson.FromJson<List<int>>();
}
}Save this as JsonTest.cs then compile and run with mcs JsonTest.cs && mono JsonTest.exe
Simply copy and paste the JSON Parser and/or the JSON Writer into your project. I also provide NuGet but I recommend the copy paste route ;)
| Back | FazBrowse Home | New Git URL |