diff --git a/Funktions/Json_Parse_Example.cs b/Funktions/Json_Parse_Example.cs new file mode 100644 index 0000000..f64fdde --- /dev/null +++ b/Funktions/Json_Parse_Example.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json; +using System.Net; + + +class JsonParser +{ + // Json file location + string json_url = "https://git.weifer.org/weifer/Pruefungskatalog/raw/branch/master/assets/questions_answers.json"; + + string get_questions = ""; + string get_answer = ""; + + // Get Data + dynamic get_jsonData(string url) + { + var webclient = new WebClient(); + string json = webclient.DownloadString(url); + dynamic dynJson = JsonConvert.DeserializeObject(json); + return dynJson; + + } + // Returns random String from a Random Json Object in JsonData + void get_question() + { + dynamic json_data = get_jsonData(json_url); + int count = json_data.Count; // Count Json Objects + int random_number = new Random().Next(0, count); // Random number between 0, and all Json Objects + + get_questions = json_data[random_number][$"{random_number}"]["question"]; + get_answer = json_data[random_number][$"{random_number}"]["answer"]; + + } +} \ No newline at end of file