IDataStore.ImportJson(string json, DwBuffer dwbuffer, int startRow, int endRow, int startColumn, int endColumn) Method
.NET Standard 2.x | Current Version (1.0.1) 
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 you can specify the number of the first key value and the number of the last key value in the JSON object to be imported. Data that are out of this range will not be imported into the DataStore.
Namespace: PowerBuilder.Data
Assembly: PowerBuilder.Data.dll
Syntax
public int ImportJson(string json, DwBuffer dwbuffer, int startRow, int endRow, int startColumn, int endColumn);
Parameters
json System.String
A string specifying the JSON data.
The JSON string must comply with the plain-format JSON or DataWindow JSON.
dwbuffer PowerBuilder.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 between the starting row and the ending row and from between the starting column and the ending column in a JSON string to the specified buffer.
using PowerBuilder.Data;
using System;
using System.IO;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class ImportJsonExample
{
private SchoolContext _context;
public ImportJsonExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example6()
{
// Instantiates the datastore with datawindow: d_department2.
// d_department2 has no departmentID column
var datastore = new DataStore("d_department2", _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 JSON to the DataStore primary buffer
// from row 1 through the end.
// Imports data starting from column 2 and imports only one column,
// so only column 2 is imported.
datastore.ImportJson(json, DwBuffer.Primary, 0, 3, 1, 1);
Console.WriteLine("Rowcount:{0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("Name:{0}; Budget:{1}",
datastore.GetItem<string>(row, "name"),
datastore.GetItem<decimal>(row, "budget"));
}
datastore.Reset();
// Imports data from row 2 and 3 of the JSON string to the primary buffer
// Imports data starting from column 2 and imports only one column.
// So column 1 will not be imported, and only column 2 is imported.
datastore.ImportJson(json, DwBuffer.Primary, 1, 2, 1, 1);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("Name: {0}; Budget: {1}",
datastore.GetItem<string>(row, "name"),
datastore.GetItem<decimal>(row, "budget"));
}
/*This code produces the following output:
Rowcount: 4
Name: Engineering; Budget: 0
Name: English; Budget: 0
Name: Economics; Budget: 0
Name: Mathematics; Budget: 0
Rowcount: 2
Name: English; Budget: 0
Name: Economics; Budget: 0
*/
}
}
}
Example Refer To
JSON File: ImportJson8
Applies to
.NET Standard
2.x