using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public string status { get; set; }
public string message { get; set; }
public Result result { get; set; }
[JsonProperty(PropertyName = "SafeGasPrice")]
public int SafeGasPrice { get; set; }
[JsonProperty(PropertyName = "ProposeGasPrice")]
public int ProposeGasPrice { get; set; }
[JsonProperty(PropertyName = "FastGasPrice")]
public int FastGasPrice { get; set; }
public static void Test()
var responseBody = @"{""status"":""1"",""message"":""OK"",""result"":{""LastBlock"":""14296250"",""SafeGasPrice"":""96"",""ProposeGasPrice"":""96"",""FastGasPrice"":""97"",""suggestBaseFee"":""95.407119606"",""gasUsedRatio"":""0.174721033333333,0.523179548504219,0.056945596868572,0.999939743363228,0.953861217484817""}}
TestExplicit(responseBody);
TestAnonymous(responseBody);
static void TestExplicit(string responseBody)
var deserializeObject = JsonConvert.DeserializeObject<Root>(responseBody)?.result;
Console.WriteLine(deserializeObject.SafeGasPrice.ToString());
Assert.AreEqual(96, deserializeObject.SafeGasPrice);
static void TestAnonymous(string responseBody)
var deserializeObject = JsonConvert.DeserializeAnonymousType(responseBody, new { result = default(Result) })?.result;
Console.WriteLine(deserializeObject.SafeGasPrice.ToString());
Assert.AreEqual(96, deserializeObject.SafeGasPrice);
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Assembly.GetName().Name, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];