Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading