DataStoreDataExtensions.ImportJson(this IDataStoreBase dataStore, string text, DwBuffer dwbuffer, int startRow, int endRow,int startColumn, int endColumn, int dwStartColumn) Method
.NET Standard 2.x
Inserts data from a JSON string into the specified buffer of DataStore. You can specify the starting and ending positions in the JSON array, and specify the number of the first key value and the number of the last key value in the JSON object to be imported. You can also specify the number of the first column in the DataStore that should receive data.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int ImportJson(this IDataStoreBase dataStore, string text, DwBuffer dwbuffer, int startRow, int endRow, int startColumn, int endColumn, int dwStartColumn);
Parameters
text
System.String
A string specifying the JSON data.
The JSON string must comply with the plain-format JSON or DataWindow JSON.
dwbuffer
DWNet.Data.DwBuffer
The specified buffer of the DataStore.
A value of the DwBuffer
enumerated datatype identifying the DataWindow buffer
into which you want to import the data.
For plain-format JSON: Imports the JSON data to the specified buffer.
For DataWindow JSON: Imports data from the specified buffer from the JSON string to the corresponding buffer.
startRow
System.Int32
The zero-based number of the first detail object in the JSON array that you want to import. If it is negative, 0
is used.
endRow
System.Int32
The zero-based number of the last detail object in the JSON array that you want to import. If it is negative, it indicates the rest of rows.
startColumn
System.Int32
The zero-based number of the first key value in the JSON object that you want to import. If it is negative, 0
is used.
endColumn
System.Int32
The zero-based number of the last key value in the JSON object that you want to import. If it is negative, it indicates the rest of columns.
Returns
System.Int32
Returns the number of rows that were imported if it succeeds.
Examples
The following code example demonstrates how to import the department data from a range of rows and a range of columns in a JSON string to the specified buffer beginning in the specified column.
using DWNet.Data;
using System;
using System.IO;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ImportJsonExample
{
private readonly SchoolContext _context;
public ImportJsonExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example7()
{
// Instantiates the datastore with datawindow: d_department
var datastore = new DataStore("d_department", _context);
// Gets the JSON file. ImportJson8.json contains 4 records.
string path = Path.Combine(AppContext.BaseDirectory,
@"Jsons\IDatastore\ImportJson8.json");
string json = File.ReadAllText(path);
// Imports data from the first row through the end
// Imports data from the second column through the end. The first column will not be imported.
// DataStore receives data beginning in the second column, so the first column in DataStore has no data.
datastore.ImportJson(json, DwBuffer.Primary, 0, 3, 1, 10, 1);
Console.WriteLine("Rowcount:{0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("Department ID: {0}; Name:{1}",
datastore.GetItem<int>(row, "departmentid"),
datastore.GetItem<string>(row, "name"));
}
datastore.Reset();
// Imports data from the second and third rows.
// Imports data starting from the second column. So the first column will not be imported.
// Imports data starting from the second column and imports only one column.
// DataStore receives data beginning in the second column, so the first column in DataStore
// has no data.
datastore.ImportJson(json, DwBuffer.Primary, 1, 2, 1, 1, 1);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("Department ID: {0}; Name: {1}",
datastore.GetItem<int>(row, "departmentid"),
datastore.GetItem<string>(row, "name"));
}
/*This code produces the following output:
Rowcount: 4
Department ID: 0; Name: Engineering
Department ID: 0; Name: English
Department ID: 0; Name: Economics
Department ID: 0; Name: Mathematics
Rowcount: 2
Department ID: 0; Name: Engineering
Department ID: 0; Name: English
*/
}
}
}
Example Refer To
Model Class: D_Department
JSON File: ImportJson8
DataWindow File: d_department
Applies to
.NET Standard
2.x