New API sugar to create Json objects from strings

March 4, 2015 1:43 pm Published by Leave your thoughts

Starcounter versions prior to 2.0.3066.3 support the following syntax to create a Json object from a string:

string str = @"{ ""Key"": ""value"", ""Number"": 3}";
TObject t = TObject.CreateFromJson(str);
dynamic json = new Json() { Template = t };

Console.WriteLine(json.Key + " : " + json.Number); // Will print 'value : 3'

Starting from first version after 2.0.3066.3, it is possible to use the new Json constructor overload that takes string as a parameter:

string str = @"{ ""Key"": ""value"", ""Number"": 3}";
dynamic json = new Json(str);

Console.WriteLine(json.Key + " : " + json.Number); // Will print 'value : 3'

Related issue: #2571

Categorised in:

This post was written by Marcin Warpechowski

Leave a Reply

Your email address will not be published. Required fields are marked *