Wednesday, September 13, 2017

Fish a single property deeply nested in a JSON file out with a JavaScriptSerializer in C#!

public string GetConnectionString(string pathToFile)
{
   string text = System.IO.File.ReadAllText(pathToFile);
   JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
   var jsonObject = javaScriptSerializer.Deserialize<dynamic>(text);
   return jsonObject["Data"]["DefaultConnection"]["ConnectionString"];
}

No comments:

Post a Comment