Ramesh Kumar N
Ramesh Kumar N

Reputation: 3

How to extract data from JSON in ASP.NET using c#

{"pometek.net":{"status":"available","classkey":"dotnet"},"pometek.com":{"status":"available","classkey":"domcno"}} 

I want to dispense this in table format. Need help.

Upvotes: 0

Views: 1724

Answers (2)

Rawling
Rawling

Reputation: 50184

You shouldn't need a third-party library; the out-of-the-box JavaScriptSerializer can handle this.

class Item {
    public string status { get; set; }
    public string classkey { get; set; }
}

var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
var input = "{\"pometek.net\":{\"status\":\"available\",\"classkey\":\"dotnet\"},\"pometek.com\":{\"status\":\"available\",\"classkey\":\"domcno\"}}";
var results = jss.Deserialize<Dictionary<string, Item>(input);
var query = results["pometek.net"].status; // = "available"

Displaying this as a table is a separate step.

Upvotes: 1

Stefan P.
Stefan P.

Reputation: 9519

You can use Json.NET to deserialize the json object into a C# class, and then map that class to a table format in asp.net

Upvotes: 2

Related Questions