HTML to JSON C#

Les pages HTML sont chargées dans les navigateurs et affichent tous les types de données. Parfois, vous pourriez vouloir extraire des données d’un fichier HTML et le convertir en JSON, un format léger, lisible par l’homme qui est largement utilisé pour l’échange de données entre un serveur et un client. Dans cet article, je vais vous suivre comment convertir HTML à JSON en utilisant C#.

Les sujets que nous allons couvrir sont :

HTML à JSON Converter C# API

To convert HTML to JSON, we’re using the powerful and easy-to-use Aspose.Cells JSON Converter pour .NET.

The Livre de travail 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 ExportRangeToJsonOptions class to set your export options. You then create a range from cells with the Création( ) method provided by the Les cellules class. Finally, you call the JsonUtility.ExportRangeToJson() method to generate your JSON string.

If you want to get started, you can either Téléchargez le DLL or install it directly from Nouveau:

PM> Install-Package Aspose.Cells

Convertir HTML à JSON en C#

Le processus de conversion HTML en JSON avec C# est simple :

  • Téléchargez le fichier HTML: Commencez par ouvrir le fichier HTML en utilisant la classe Workbook.
  • Cettez vos options d’exportation: Créez une instance de la classe ExportRangeToJsonOptions.
  • Définissez une gamme de cellules: Utilisez la méthode CreateRange() pour créer une gamme de cellules.
  • Exporter à JSON: Convertez la gamme sélectionnée en un fil JSON en utilisant JsonUtility.ExportRangeToJson().
  • Save your JSON data: Écrivez la ligne JSON résultante à un fichier en utilisant File.WriteAllText().

L’exemple de code ci-dessous montre comment convertir HTML à JSON en utilisant C#:

Convert HTML to JSON in C#

Obtenez une licence gratuite

You can try the library without any limitations by obtaining a Licence temporaire gratuite.

Conclusion

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 La documentation or ask questions on the Forum.

More in this category