JSONをCSVに変換する
Contents
[
Hide
]
JSONをCSVに変換
Aspose.Cells for Python via .NETは、単純なJSONおよびネストされたJSONをCSVに変換する機能をサポートしています。このために、APIはJsonLayoutOptionsおよびJsonUtilityクラスを提供しています。JsonLayoutOptionsクラスはJSONのレイアウトに関するオプションを提供します。
以下のコードサンプルは、ソースのJSONファイルをロードして出力のCSVファイルを生成する方法を示しています。
サンプルコード
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
from aspose.cells import Workbook | |
from aspose.cells.utility import JsonLayoutOptions, JsonUtility | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Read JSON file | |
str = open(sourceDir + "SampleJson.json", "r").read() | |
# Create empty workbook | |
workbook = Workbook() | |
# Get Cells | |
cells = workbook.worksheets[0].cells | |
# Set JsonLayoutOptions | |
importOptions = JsonLayoutOptions() | |
importOptions.convert_numeric_or_date = True | |
importOptions.array_as_table = True | |
importOptions.ignore_array_title = True | |
importOptions.ignore_object_title = True | |
JsonUtility.import_data(str, cells, 0, 0, importOptions) | |
# Save Workbook | |
workbook.save(outputDir + str(r"SampleJson_out.csv")) |