Hi itsbaala,
Refer below code.
HTML
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Namespaces
C#
using System.Data;
using System.Net;
using Newtonsoft.Json;
VB.Net
Imports System.Data
Imports System.Net
Imports Newtonsoft.Json
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://api.elsevier.com/content/search/sciencedirect?query=gene&apiKey=API_Key";
WebClient client = new WebClient();
string reply = client.DownloadString(url);
Root root = JsonConvert.DeserializeObject<Root>(reply);
DataTable dt = new DataTable();
dt.Columns.Add("LoadDate");
dt.Columns.Add("DcIdentifier");
dt.Columns.Add("Link");
foreach (Entry entry in root.SearchResults.entry)
{
DataRow dr = dt.NewRow();
foreach (Link link in entry.link)
{
dr["LoadDate"] = entry.LoadDate;
dr["DcIdentifier"] = entry.DcIdentifier;
dr["Link"] = link.Href;
dt.Rows.Add(dr.ItemArray);
}
}
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
public class Root
{
[JsonProperty("search-results")]
public SearchResults SearchResults { get; set; }
}
public class SearchResults
{
[JsonProperty("opensearch:totalResults")]
public string OpensearchTotalResults { get; set; }
[JsonProperty("opensearch:startIndex")]
public string OpensearchStartIndex { get; set; }
[JsonProperty("opensearch:itemsPerPage")]
public string OpensearchItemsPerPage { get; set; }
[JsonProperty("opensearch:Query")]
public OpensearchQuery OpensearchQuery { get; set; }
public List<Link> link { get; set; }
public List<Entry> entry { get; set; }
}
public class OpensearchQuery
{
[JsonProperty("@role")]
public string Role { get; set; }
[JsonProperty("@searchTerms")]
public string SearchTerms { get; set; }
[JsonProperty("@startPage")]
public string StartPage { get; set; }
}
public class Link
{
[JsonProperty("@ref")]
public string Ref { get; set; }
[JsonProperty("@href")]
public string Href { get; set; }
[JsonProperty("@type")]
public string Type { get; set; }
}
public class Entry
{
[JsonProperty("load-date")]
public DateTime LoadDate { get; set; }
public List<Link> link { get; set; }
[JsonProperty("dc:identifier")]
public string DcIdentifier { get; set; }
}
public class Authors
{
public object author { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim url As String = "https://api.elsevier.com/content/search/sciencedirect?query=gene&apiKey=API_Key"
Dim client As WebClient = New WebClient()
Dim reply As String = client.DownloadString(url)
Dim root As Root = JsonConvert.DeserializeObject(Of Root)(reply)
Dim dt As DataTable = New DataTable()
dt.Columns.Add("LoadDate")
dt.Columns.Add("DcIdentifier")
dt.Columns.Add("Link")
For Each entry As Entry In root.SearchResults.entry
Dim dr As DataRow = dt.NewRow()
For Each link As Link In entry.link
dr("LoadDate") = entry.LoadDate
dr("DcIdentifier") = entry.DcIdentifier
dr("Link") = link.Href
dt.Rows.Add(dr.ItemArray)
Next
Next
gvDetails.DataSource = dt
gvDetails.DataBind()
End Sub
Public Class Root
<JsonProperty("search-results")>
Public Property SearchResults As SearchResults
End Class
Public Class SearchResults
<JsonProperty("opensearch:totalResults")>
Public Property OpensearchTotalResults As String
<JsonProperty("opensearch:startIndex")>
Public Property OpensearchStartIndex As String
<JsonProperty("opensearch:itemsPerPage")>
Public Property OpensearchItemsPerPage As String
<JsonProperty("opensearch:Query")>
Public Property OpensearchQuery As OpensearchQuery
Public Property link As List(Of Link)
Public Property entry As List(Of Entry)
End Class
Public Class OpensearchQuery
<JsonProperty("@role")>
Public Property Role As String
<JsonProperty("@searchTerms")>
Public Property SearchTerms As String
<JsonProperty("@startPage")>
Public Property StartPage As String
End Class
Public Class Link
<JsonProperty("@ref")>
Public Property Ref As String
<JsonProperty("@href")>
Public Property Href As String
<JsonProperty("@type")>
Public Property Type As String
End Class
Public Class Entry
<JsonProperty("load-date")>
Public Property LoadDate As DateTime
Public Property link As List(Of Link)
<JsonProperty("dc:identifier")>
Public Property DcIdentifier As String
End Class
Public Class Authors
Public Property author As Object
End Class
Screenshot