Jit. Best serialization method for json

I need to create custom json for jit library . Should I use additional C # logic or somehow extend the JsonSerializer. Json should be like this β†’

var json = { "children": [ { "children": [ { "children": [], "data": { "playcount": "276", "$color": "#8E7032", "image": "http://userserve-ak.last.fm/serve/300x300/11403219.jpg", "$area": 276 }, "id": "album-Thirteenth Step", "name": "Thirteenth Step" } }] 

}

+6
source share
4 answers

Using Json.Net

 public void Test() { Node root = new Node(); Node child = new Node(); Data data = new Data() { Area = 276, Color = "#8E7032", PlayCount = "276", Image = "http://userserve-ak.last.fm/serve/300x300/11403219.jpg" }; Node grandChild = new Node() { Id = "album-Thirteenth Step", Name = "Thirteenth Step", Data = data }; root.Children.Add(child); child.Children.Add(grandChild); var json = JsonConvert.SerializeObject( root, new JsonSerializerSettings() { NullValueHandling= NullValueHandling.Ignore, Formatting= Newtonsoft.Json.Formatting.Indented }); } public class Node { [JsonProperty("children")] public List<Node> Children = new List<Node>(); [JsonProperty("data")] public Data Data; [JsonProperty("id")] public string Id; [JsonProperty("name")] public string Name; } public class Data { [JsonProperty("playcount")] public string PlayCount; [JsonProperty("$color")] public string Color; [JsonProperty("image")] public string Image; [JsonProperty("$area")] public int Area; } 
+4
source

Do you have about Json.net?

http://json.codeplex.com/

At least you will have a good level of room setup + best serializer

+1
source

json is the best json tool

+1
source

ServiceStack.Text is the fastest.

For benchmarks: http://www.servicestack.net/benchmarks/

0
source

Source: https://habr.com/ru/post/918169/


All Articles