Skip to content

Instantly share code, notes, and snippets.

@areee
Last active April 17, 2021 08:30
Show Gist options
  • Save areee/0b43298ec3bb666630fc32a59b939894 to your computer and use it in GitHub Desktop.
Save areee/0b43298ec3bb666630fc32a59b939894 to your computer and use it in GitHub Desktop.

About json file

{
"adultAB": [ 47.1, 62.7, 125.4, 188.1, 627.3 ],
"discountAB": [ 23.6, 31.4, 62.8, 94.2, 314.0 ],
"studentAB": [ 25.9, 34.5, 69.0, 103.5, 344.7 ],
"adultABC": [ 74.8, 99.7, 199.4, 299.1, 997.3 ],
"discountABC": [ 37.5, 49.9, 99.8, 149.7, 498.7 ],
"studentABC": [ 41.1, 54.8, 109.6, 164.4, 548.0 ],
"adultCD": [ 60.5, 80.6, 161.2, 241.8, 806.3 ],
"discountCD": [ 30.3, 40.3, 80.6, 120.9, 403.3 ],
"studentCD": [ 33.3, 44.3, 88.6, 132.9, 443.6 ],
"adultABCD": [ 107.2, 142.7, 285.4, 428.1, 1427.3 ],
"discountABCD": [ 53.8, 71.4, 142.8, 214.2, 713.7 ],
"studentABCD": [ 59.0, 78.5, 157.0, 235.5, 785.6 ]
}
using System;
using System.IO;
using System.Text.Json;
namespace Sandbox
{
class MainClass
{
public static void Main(string[] args)
{
var currentDirectory = Directory.GetCurrentDirectory();
string delimiter = Environment.OSVersion.Platform.Equals(PlatformID.Unix) ? "/" : "\\";
var filesDirectory = currentDirectory + delimiter + "Files";
Directory.SetCurrentDirectory(filesDirectory);
string jsonAsString = File.ReadAllText(Directory.GetCurrentDirectory() + delimiter + "prices.json");
var jsonDocument = JsonDocument.Parse(jsonAsString);
Console.WriteLine(jsonDocument.RootElement); // An example to show that we have parsed our json file
/*
* Continue implementing, e.g. read json as .NET objects
* https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-5-0#how-to-read-json-as-net-objects-deserialize
*/
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment