We help IT Professionals succeed at work.

Read JSON Data in C#.net

chelsea17
chelsea17 asked
on
110 Views
Last Modified: 2019-03-20
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
Comment
Watch Question

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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

Author

Commented:
once i create the class how to call the values i want ?
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.