1234567891011121314151617181920212223242526 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using Newtonsoft.Json;
- namespace EthermineBotTelegramCore
- {
- public class JsonDownloader
- {
- public static T _download_serialized_json_data<T>(string url) where T : new() {
- using (var w = new WebClient()) {
- var jsonData = string.Empty;
- // attempt to download JSON data as a string
- try
- {
- jsonData = w.DownloadString(url);
- jsonData = jsonData.Replace("null", "0");
- }
- catch (Exception) { }
- // if string with JSON data is not empty, deserialize it to class and return its instance
- return !string.IsNullOrEmpty(jsonData) ? JsonConvert.DeserializeObject<T>(jsonData) : new T();
- }
- }
- }
- }
|