JsonDataSource

JsonDataSource(string)

使用解析 JSON 数据的默认选项,使用来自 JSON 文件的数据创建新的数据源。

public JsonDataSource(string jsonPath)
范围类型描述
jsonPathString用作数据源的 JSON 文件的路径。

也可以看看


JsonDataSource(Stream)

使用解析 JSON 数据的默认选项,创建一个包含 JSON 流数据的新数据源。

public JsonDataSource(Stream jsonStream)
范围类型描述
jsonStreamStream用作数据源的 JSON 数据流。

也可以看看


JsonDataSource(string, JsonDataLoadOptions)

使用指定的选项解析 JSON 数据,创建一个包含 JSON 文件中数据的新数据源。

public JsonDataSource(string jsonPath, JsonDataLoadOptions options)
范围类型描述
jsonPathString用作数据源的 JSON 文件的路径。
optionsJsonDataLoadOptions解析 JSON 数据的选项。

例子

展示如何使用 JSON 作为数据源(字符串)。

Document doc = new Document(MyDir + "Reporting engine template - JSON data destination.docx");

JsonDataLoadOptions options = new JsonDataLoadOptions
{
    ExactDateTimeParseFormats = new List<string> {"MM/dd/yyyy", "MM.d.yy", "MM d yy"},
    AlwaysGenerateRootObject = true,
    PreserveSpaces = true,
    SimpleValueParseMode = JsonSimpleValueParseMode.Loose
};

JsonDataSource dataSource = new JsonDataSource(MyDir + "List of people.json", options);
BuildReport(doc, dataSource, "persons");

doc.Save(ArtifactsDir + "ReportingEngine.JsonDataString.docx");

也可以看看


JsonDataSource(Stream, JsonDataLoadOptions)

使用指定的选项解析 JSON 数据,创建一个包含 JSON 流数据的新数据源。

public JsonDataSource(Stream jsonStream, JsonDataLoadOptions options)
范围类型描述
jsonStreamStream用作数据源的 JSON 数据流。
optionsJsonDataLoadOptions解析 JSON 数据的选项。

例子

展示如何使用 JSON 作为数据源(流)。

Document doc = new Document(MyDir + "Reporting engine template - JSON data destination.docx");

JsonDataLoadOptions options = new JsonDataLoadOptions
{
    ExactDateTimeParseFormats = new List<string> {"MM/dd/yyyy", "MM.d.yy", "MM d yy"}
};

using (FileStream stream = File.OpenRead(MyDir + "List of people.json"))
{
    JsonDataSource dataSource = new JsonDataSource(stream, options);
    BuildReport(doc, dataSource, "persons");
}

doc.Save(ArtifactsDir + "ReportingEngine.JsonDataStream.docx");

也可以看看