Hi maideen,
Please refer below sample.
HTML
<asp:Label ID="lblToken" runat="server"></asp:Label>
Namespaces
C#
using System.IO;
using Newtonsoft.Json;
VB.Net
Imports System.IO
Imports Newtonsoft.Json
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StreamReader stReader = new System.IO.StreamReader(Server.MapPath("JsonIndexing.json"));
RootObject root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(stReader.ReadToEnd());
lblToken.Text = string.Format("token: <b>{0}</b>", root.accessTokenResponse.token);
}
public class RootObject
{
public accessTokenResponse accessTokenResponse { get; set; }
}
public class accessTokenResponse
{
public string token { get; set; }
public string token_type { get; set; }
public string expires_in_seconds { get; set; }
public string client_id { get; set; }
public responseStatus responseStatus { get; set; }
}
public class responseStatus
{
public string code { get; set; }
public string message { get; set; }
public string messageDetails { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim stReader As System.IO.StreamReader = New System.IO.StreamReader(Server.MapPath("JsonIndexing.json"))
Dim root As RootObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of RootObject)(stReader.ReadToEnd())
lblToken.Text = String.Format("token: <b>{0}</b>", root.accessTokenResponse.token)
End Sub
Public Class RootObject
Public Property accessTokenResponse As accessTokenResponse
End Class
Public Class accessTokenResponse
Public Property token As String
Public Property token_type As String
Public Property expires_in_seconds As String
Public Property client_id As String
Public Property responseStatus As responseStatus
End Class
Public Class responseStatus
Public Property code As String
Public Property message As String
Public Property messageDetails As String
End Class
Json
{
"accessTokenResponse":
{
"token": "xxxxxxxxx",
"token_type": "Bearer",
"expires_in_seconds": "48114",
"client_id": "xxxxxx",
"responseStatus":
{
"code": "100000",
"message": "Service operation completed successfully",
"messageDetails": "Access token assigned."
}
}
}
Output
token: xxxxxxxxx