
Halaman HTML memuat di browser dan menampilkan semua jenis data.Kadang-kadang Anda mungkin ingin mengekstrak data dari file HTML dan mengkonversi ke JSON, format ringan, dapat dibaca oleh manusia yang digunakan secara luas untuk pertukaran data antara server dan klien.Dalam artikel ini, saya akan berjalan Anda melalui bagaimana untuk mengkonversi HTML ke JSON menggunakan C#.
Topik yang akan kami tutup adalah:
HTML untuk JSON Converter C# API
To convert HTML to JSON, we’re using the powerful and easy-to-use Aspose.Cells JSON Converter untuk .NET.
The Buku Kerja class represents a spreadsheet and can load HTML files. Each workbook may contain several worksheets, and you can even combine or copy data between them. To export a specific range as JSON, the API uses the EksporRangeToJsonOptions class to set your export options. You then create a range from cells with the Penciptaan ( method provided by the Sel class. Finally, you call the JsonUtility.ExportRangeToJson() method to generate your JSON string.
If you want to get started, you can either Download dari DLL or install it directly from NUGET:
PM> Install-Package Aspose.Cells
Konversi HTML ke JSON dalam C#
Proses untuk mengkonversi HTML ke JSON dengan C# adalah sederhana:
- Mengunggah file HTML: Mulai dengan membuka file HTML menggunakan kelas Workbook.
- Set pilihan ekspor Anda: Buat contoh dari kelas ExportRangeToJsonOptions.
- Tentukan rentang sel: Gunakan metode CreateRange() untuk membuat rentang sel.
- Export ke JSON: Konversi rentang yang dipilih ke string JSON menggunakan JsonUtility.ExportRangeToJson().
- Simpan data JSON Anda: Tulis baris JSON yang dihasilkan ke file menggunakan File.WriteAllText().
Contoh kode di bawah ini menunjukkan bagaimana untuk menukar HTML ke JSON menggunakan C#:

Dapatkan Lisensi Gratis
You can try the library without any limitations by obtaining a lisensi sementara gratis.
Kesimpulan
In this article, we explored how to extract data from an HTML file and convert it into JSON using C#. We covered loading the file, configuring the export settings, creating a cell range, and finally generating and saving the JSON string. For more details about the API, check out the Dokumentasi or ask questions on the Forum.
More in this category
- Cara Mengkonversi Excel ke Format Teks (CSV, TS V, XML) dengan Aspose.Cells untuk .NET
- Cara Mengunci dan Melindungi Excel Spreadsheets dengan Aspose.Cells untuk .NET
- Konversi Excel ke Gambar menggunakan Aspose.Cells untuk .NET Plugin
- Konversi Excel ke JSON dan Json ke Excel dengan Aspose.Cells untuk .NET
- Excel ke PDF: Plugin Konverter PDF Aspose.Cells untuk .NET