Avatar of chelsea17
 asked on

Read JSON Data in C#.net

I am pulling data from an API and I believe it is returned as a JSON string, how can I read certain data from the string ?  There are rows of data I want to loop through and put in a datatable, but can not figure out how to extract the data.

I have attached 3 files - the first 2 is the data I want to access, the third is the name of the columns.

Path to Column NamesWhere the data is - Label and Value are two fields inside I want to access.Path To Data

Avatar of undefined
Last Comment

8/22/2022 - Mon

check a look to that online tools : http://json2csharp.com/
I will create classes reprensenting your JSON object to use with : https://github.com/JamesNK/Newtonsoft.Json/

for example :

Open in new window

give :
public class Ik
    public int a { get; set; }

public class RootObject
    public string ok { get; set; }
    public List<Ik> ik { get; set; }

Open in new window


once i create the class how to call the values i want ?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

i get the error - Argument 1: cannot convert from 'string' to 'System.IO.TextReader'      

on this Deserialize(reportData, typeof(Rootobject));

this is the code

            var reportData = restResponse.Content;

            JsonSerializer serializer = new JsonSerializer();

            Rootobject datafromreport = (Rootobject)serializer.Deserialize(reportData, typeof(Rootobject));

            string strOK = datafromreport.allData.ToString();

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.