Last active
December 19, 2017 13:47
-
-
Save TheWaWaR/06d4e41e6b5ca90464566db6e80f2b32 to your computer and use it in GitHub Desktop.
C# Json.Net serialize Dictionary<string, object>. You can run it on: http://rextester.com/JOT81793
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Rextester.Program.Main is the entry point for your code. Don't change it. | |
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace Rextester | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Dictionary<string, object> points = new Dictionary<string, object> | |
{ | |
{ "James", 9001 }, | |
{ "Jo", "This is a string" }, | |
{ "Jess", null } | |
}; | |
points.Add("array", new object[]{"a", "b", 3}); | |
string json = JsonConvert.SerializeObject(points, Formatting.Indented); | |
Console.WriteLine(json); | |
// { | |
// "James": 9001, | |
// "Jo": 3474, | |
// "Jess": 11926 | |
// "array": [ | |
// "a", | |
// "b", | |
// 3 | |
// ] | |
// } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment