Hi ramco1917,
Please refer below sample.
Json
{
"kind": "youtube#videoCategoryListResponse",
"etag": "fIIv2-q7-AkaOeJf0LPrlnu-0As",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "grPOPYEUUZN3ltuDUGEWlrTR90U",
"id": "1",
"snippet": {
"title": "Film & Animation",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
},
{
"kind": "youtube#videoCategory",
"etag": "Q0xgUf8BFM8rW3W0R9wNq809xyA",
"id": "2",
"snippet": {
"title": "Autos & Vehicles",
"assignable": true,
"channelId": "UCBR8-60-B28hp2BmDPdntcQ"
}
}
]
}
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using Newtonsoft.Json;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.IO
Imports Newtonsoft.Json
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string json = File.ReadAllText(Server.MapPath("~/Json.json"));
Root root = JsonConvert.DeserializeObject<Root>(json);
foreach (Item item in root.items)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Table (Id,Title,Kind) VALUES (@Id,@Title,@Kind)", con))
{
cmd.Parameters.AddWithValue("@Id", item.id);
cmd.Parameters.AddWithValue("@Title", item.kind);
cmd.Parameters.AddWithValue("@Kind", item.snippet.title);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
public class Root
{
public string kind { get; set; }
public string etag { get; set; }
public List<Item> items { get; set; }
}
public class Item
{
public string kind { get; set; }
public string etag { get; set; }
public string id { get; set; }
public Snippet snippet { get; set; }
}
public class Snippet
{
public string title { get; set; }
public bool assignable { get; set; }
public string channelId { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim json As String = File.ReadAllText(Server.MapPath("~/Json.json"))
Dim root As Root = JsonConvert.DeserializeObject(Of Root)(json)
For Each item As Item In root.items
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("INSERT INTO Table (Id,Title,Kind) VALUES (@Id,@Title,@Kind)", con)
cmd.Parameters.AddWithValue("@Id", item.id)
cmd.Parameters.AddWithValue("@Title", item.kind)
cmd.Parameters.AddWithValue("@Kind", item.snippet.title)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Next
End Sub
Public Class Root
Public Property kind As String
Public Property etag As String
Public Property items As List(Of Item)
End Class
Public Class Item
Public Property kind As String
Public Property etag As String
Public Property id As String
Public Property snippet As Snippet
End Class
Public Class Snippet
Public Property title As String
Public Property assignable As Boolean
Public Property channelId As String
End Class