CSV'i JSON'e dönüştür
Contents
[
Hide
]
CSV’i JSON’e dönüştür
Aspose.Cells, CSV’in JSON’e dönüştürülmesini destekler. Bunun için API şunları sağlar:ExportRangeToJsonOptionsveJsonUtility sınıflar. bu**ExportRangeToJsonOptions**class, aralığı JSON’e dışa aktarma seçeneklerini sağlar.**ExportRangeToJsonOptions**sınıf aşağıdaki özelliklere sahiptir.
- ExportAsString: Bu, hücrelerin dize değerini JSON olarak dışa aktarır.
- HasHeaderRow: Bu, aralığın bir başlık satırı içerip içermediğini gösterir.
- Girinti: Girintiyi gösterir.
bu**JsonUtility**class ile ayarlanan dışa aktarma seçeneklerini kullanarak JSON’i dışa aktarır.**ExportRangeToJsonOptions**sınıf.
Aşağıdaki kod örneği, kullanımını gösterir**ExportRangeToJsonOptions**ve**JsonUtility** yüklemek için sınıflarkaynak CSV dosyasıve konsolda JSON çıktısını yazdırır.
Basit kod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Csv); | |
// Load CSV file | |
Workbook workbook = new Workbook(sourceDir + "SampleCsv.csv", loadOptions); | |
Cell lastCell = workbook.Worksheets[0].Cells.LastCell; | |
// Set JsonSaveOptions | |
JsonSaveOptions jsonSaveOptions = new JsonSaveOptions(); | |
Range range = workbook.Worksheets[0].Cells.CreateRange(0, 0, lastCell.Row + 1, lastCell.Column + 1); | |
string data = JsonUtility.ExportRangeToJson(range, jsonSaveOptions); | |
// Print JSON | |
Console.WriteLine(data); |
Konsol Çıkışı
[
{
"id": 1,
"language": "Java",
"edition": "third",
"author": "Herbert Schildt",
"streetAddress": 126,
"city": "San Jone",
"state": "CA",
"postalCode": 394221
},
{
"id": 2,
"language": "C++",
"edition": "second",
"author": "EAAAA",
"streetAddress": 126,
"city": "San Jone",
"state": "CA",
"postalCode": 394221
},
{
"id": 3,
"language": ".Net",
"edition": "second",
"author": "E.Balagurusamy",
"streetAddress": 126,
"city": "San Jone",
"state": "CA",
"postalCode": 394221
}
]