Home > other >  Read specific name field from Json data and assign to a string variable
Read specific name field from Json data and assign to a string variable

Time:02-23

I want a name field of this json data to have its own string variable, so that I can only display this variable in the application and not the whole data.

Problem

I don't know where to start.

Screenshot

CodePudding user response:

You need a class for this json like:

public class YourClass
{
    public int LastBlock { get; set; }
    public int SafeGasPrice { get; set; }
    public int ProposeGasPrice { get; set; }
    public int FastGasPrice { get; set; }
    // Your screenshot is cut. Your should post your json normally but you get the point
}

You need to add a nuget package called Newtonsoft.Json.

After that in your code you can deserialise your json like this:

YourClass DeserializedObject = JsonConvert.DeserializeObject<YourClass>(Your Json Content in here);

Finally you can access the desired value like this:

int accessedValue = DeserializedObject.LastBlock;
  • Related