Hi itsbaala,
Check this example. Now please take its reference and correct your code.
HTML
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Namespaces
C#
using System.Net;
using Newtonsoft.Json;
VB.Net
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);
gvDetails.DataSource = root.SearchResults.entry;
gvDetails.DataBind();
}
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("@_fa")]
public string Fa { get; set; }
[JsonProperty("@ref")]
public string Ref { get; set; }
[JsonProperty("@href")]
public string Href { get; set; }
[JsonProperty("@type")]
public string Type { get; set; }
}
public class Authors
{
public object author { get; set; }
}
public class Entry
{
[JsonProperty("@_fa")]
public string Fa { get; set; }
[JsonProperty("load-date")]
public DateTime LoadDate { get; set; }
public List<Link> link { get; set; }
[JsonProperty("dc:identifier")]
public string DcIdentifier { get; set; }
[JsonProperty("prism:url")]
public string PrismUrl { get; set; }
[JsonProperty("dc:title")]
public string DcTitle { get; set; }
[JsonProperty("dc:creator")]
public string DcCreator { get; set; }
[JsonProperty("prism:publicationName")]
public string PrismPublicationName { get; set; }
[JsonProperty("prism:volume")]
public string PrismVolume { get; set; }
[JsonProperty("prism:coverDate")]
public string PrismCoverDate { get; set; }
[JsonProperty("prism:startingPage")]
public string PrismStartingPage { get; set; }
[JsonProperty("prism:endingPage")]
public string PrismEndingPage { get; set; }
[JsonProperty("prism:doi")]
public string PrismDoi { get; set; }
public bool openaccess { get; set; }
public string pii { get; set; }
public Authors authors { 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 Root
{
[JsonProperty("search-results")]
public SearchResults SearchResults { 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)
gvDetails.DataSource = root.SearchResults.entry
gvDetails.DataBind()
End Sub
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("@_fa")>
Public Property Fa As String
<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 Authors
Public Property author As Object
End Class
Public Class Entry
<JsonProperty("@_fa")>
Public Property Fa As String
<JsonProperty("load-date")>
Public Property LoadDate As DateTime
Public Property link As List(Of Link)
<JsonProperty("dc:identifier")>
Public Property DcIdentifier As String
<JsonProperty("prism:url")>
Public Property PrismUrl As String
<JsonProperty("dc:title")>
Public Property DcTitle As String
<JsonProperty("dc:creator")>
Public Property DcCreator As String
<JsonProperty("prism:publicationName")>
Public Property PrismPublicationName As String
<JsonProperty("prism:volume")>
Public Property PrismVolume As String
<JsonProperty("prism:coverDate")>
Public Property PrismCoverDate As String
<JsonProperty("prism:startingPage")>
Public Property PrismStartingPage As String
<JsonProperty("prism:endingPage")>
Public Property PrismEndingPage As String
<JsonProperty("prism:doi")>
Public Property PrismDoi As String
Public Property openaccess As Boolean
Public Property pii As String
Public Property authors As Authors
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 Root
<JsonProperty("search-results")>
Public Property SearchResults As SearchResults
End Class
Screenshot