Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Download Json String From URL Using Web Client And Convert Json To Datatable In ASP.NET
WhatsApp
Nikhil Sangani
Aug 07
2016
11.1
k
0
0
string str =
"type your json url here"
;
WebClient webClient =
new
WebClient();
if
(webClient ==
null
) {
webClient =
new
WebClient();
}
else
{
webClient.Dispose();
webClient =
null
;
webClient =
new
WebClient();
}
DataTable JsonDataTable =
new
DataTable();
//Set Header
webClient.Headers[
"User-Agent"
] =
"Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
;
//Download Content
string JsonSting = webClient.DownloadString(str);
//Convert JSON to Datatable
JsonDataTable = (DataTable) JsonConvert.DeserializeObject(JsonSting, (
typeof
(DataTable)));
JsonDataTable.TableName =
"JSON_MAST"
;
Json String
Web Client
Convert Json
Datatable
ASP.NET
Up Next
How To Download Json String From URL Using Web Client And Convert Json To Datatable In ASP.NET