[DEVEXPRESS] Hướng dẫn load Json DataSource vào GridView
Dưới đây, là giao diện demo ứng dụng:Ở bài viết, này các bạn có đọc dữ liệu json từ file hoặc request từ web API.
Full source code C#:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using DevExpress.DataAccess.Json; namespace JsonBinddingGridView { public partial class Form1 : DevExpress.XtraEditors.XtraForm { public Form1() { InitializeComponent(); } protected override void OnShown(EventArgs e) { base.OnShown(e); // 1. Get json from file var jsonDataSource = new JsonDataSource(); Uri fileUri = new Uri("data.json", UriKind.RelativeOrAbsolute); jsonDataSource.JsonSource = new UriJsonSource(fileUri); // 2. Get json from API Website //var jsonDataSource = new JsonDataSource(); //jsonDataSource.JsonSource = new UriJsonSource( // new Uri("https://raw.githubusercontent.com/dinhtona/api-mssql-dapper/main/db.json")); jsonDataSource.Fill(); gridControl1.DataSource = jsonDataSource; } } }
Ở đoạn code trên các bạn có thể bỏ comment số 2, để chạy test load từ web API nhé.
Qua bài viết này các bạn có thể hiểu sơ bộ về việc lấy dữ liệu từ những file JSON như trên facebook chẳng hạn, để người dùng lấy id, email, họ tên, địa chỉ chẳng hạn vâ được in lên listbox hoặc listview để người dùng kiểm tra.
Hoặc có thể download bộ code bên dưới để tìm hiểu thêm nhé.
Chúc mọi người thành công với thủ thuật trên nhé.
Theo LapTrinhVB.Net
3 comments:
e chuyên về mãng này hả?
k a :D, e và thằng h` lúc xưa ít khi viết bài chia sẽ, đa phân copy về cất có khi nào cần tìm cho nhanh đó a :D
chưa tìm hiểu gì về chương trình này :D nói chung là k hiểu gì haha
Post a Comment