Link to home
Start Free TrialLog in
Avatar of chelsea17
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.

User generated imageUser generated imageUser generated image
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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 :
[{"ok":"lol","ik":[{"a":1},{"a":1},{"a":4}]}]

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

Avatar of chelsea17
chelsea17

ASKER

once i create the class how to call the values i want ?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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