HTML to JSON C#

HTML 페이지는 브라우저에 로드하고 모든 종류의 데이터를 표시합니다.때로는 HTML 파일에서 데이터를 추출하고 JSON으로 변환하고, 서버와 클라이언트 사이의 데이터 교환에 널리 사용되는 가벼운, 인간 읽을 수있는 형식입니다.이 기사에서, 나는 C#를 사용하여 HTML에서 JSON으로 변환하는 방법을 통과 할 것입니다.

우리가 다루는 주제는 다음과 같습니다 :

HTML에서 JSON로 변환기 C# API

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

The 워크북 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 수출RangeToJsonOptions class to set your export options. You then create a range from cells with the 크리스마스( method provided by the 세포 class. Finally, you call the JsonUtility.ExportRangeToJson()에 대한 자세한 내용 method to generate your JSON string.

If you want to get started, you can either DLL 다운로드 or install it directly from 나그네:

PM> Install-Package Aspose.Cells

HTML에서 JSON으로 C#로 변환

C#를 사용하여 HTML을 JSON으로 변환하는 과정은 간단합니다.

  • **HTML 파일을 업로드하십시오: Workbook 클래스를 사용하여 HTML 파일을 열어 시작합니다.
  • 당신의 수출 옵션을 설정하십시오: ExportRangeToJsonOptions 클래스의 예를 만드십시오.
  • 세포 범위를 정의하십시오: CreateRange() 방법을 사용하여 세포 범위를 만들 수 있습니다.
  • Export to JSON: 선택한 범위를 **JsonUtility.ExportRangeToJson()**를 사용하여 JSON 스트립으로 변환합니다.
  • **JSON 데이터를 저장하십시오: **File.WriteAllText()**를 사용하여 파일에 결과 JSON 스트립을 작성합니다.

아래 코드 예제는 C#를 사용하여 HTML을 JSON으로 변환하는 방법을 보여줍니다:

Convert HTML to JSON in C#

무료 라이센스를 받으세요

You can try the library without any limitations by obtaining a 무료 임시 라이센스.

결론

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 문서화 or ask questions on the 포럼.

More in this category