Using JSON(Javascript Object Notation) datasource send data from .Net Core

Hi,

I create a list from person class that using .Net Core 5.0. and send to report but fastreport consists of a single line from the first element of the list.

      List<Person> data = GetDummyData();
      Report report = new Report();
      report.Load("C:\\Users\\testyazilim\\Desktop\\PersonJsonTest.frx");
      report.RegisterData(data, "JSON.item");
      report.Prepare();

The json format I use is as follows; and json schema is created automatically.

{
 "Id": {
  "type": "integer"
 },
 "Name": {
  "type": "string"
 },
 "Surname": {
  "type": "string"
 },
 "Age": {
  "type": "integer"
 }
}

the report is generated successfully but only from a single line, although I use a table in ".frx" report. I used many different versions of json, but the result was the same.

I use FastReport Community.

Comments

  • Hello!

    When you pass a `List<Person>` via `report.RegisterData(data, ‘JSON.item’)` in a template designed for a JSON schema (or without an explicit `DataBand.DataSource` binding), only the first item in the list is displayed because the `DataBand` is not bound to a data source or the field path in the `TextObject` does not match the registered name.

    A working solution in .NET 8:

    report.RegisterData(data, ‘Person’, maxNestingLevel: 2);
    var ds = report.GetDataSource(‘Person’);
    ds.Enabled = true;
    // Ensure that the DataBand in the .frx file or in the code has a DataSource set:
    ((DataBand)report.FindObject(‘Data1’)).DataSource = ds;
    report.Prepare();
    

    And use [Person.Name] and [Person.Age] in the fields. If a JsonDataSourceConnection is already configured in the .frx file, pass the JSON string directly to the connector’s ConnectionString (JsonDataSourceConnection) without mixing it with a List<Person>

This discussion has been closed.