Pruthvi Shetty
Pruthvi Shetty

Reputation: 11

Display JSON data in Gridview using C#

I have a JSON which looks like this -

http://plugins.cordova.io/_list/search/search?startkey=%22bar%22&endkey=%22barZZZZZ%22&limit=1000

(You may use this to pretty print it - http://jsonprettyprint.com/)

I need to parse this and display each plugin's data in a gridview under the headings - Name, ID, Description and Version. Currently, I'm able to retrieve the JSON in a string variable. What is the procedure to parse and display this in a WPF DataGridView?

TIA.

Upvotes: 0

Views: 2153

Answers (2)

Pruthvi Shetty
Pruthvi Shetty

Reputation: 11

Found the solution. After creating the class, use array objects called objPlugins to store the JSON data and eventually bind it to the DataGrid using - grdPluginList.ItemsSource = objPlugins; That's about it.

Upvotes: 1

Ifwat
Ifwat

Reputation: 1553

You need to create a class for it, after that you can display it in gridview.

A class will look like this:

public class ClassForJson
    {
        public string key { get; set; }
        public Value value{ get; set; }
        public class Value
        {
            public string name { get; set; }
            public string description { get; set; }
            public string version { get; set; }
        }
    }

After you already created the correct structure of class based on your json then you can display it in gridview by using this code:

 List<ClassForJson> q = JsonConvert.DeserializeObject<List<ClassForJson>>(results.data.ToString());  
 GridView1.DataSource = q;
 GridView1.DataBind();

Upvotes: 0

Related Questions