Show / Hide Table of Contents

    DataStoreDataExtensions.ImportJsonByKey(this IDataStoreBase dataStore, string text) Method

    .NET Standard 2.x

    Inserts data from a JSON string into the DataStore according to the key name of the JSON item.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public static int ImportJsonByKey(this IDataStoreBase dataStore, string text);
    

    Parameters

    text System.String

    A string specifying the JSON data.

    The JSON string must comply with the plain-format JSON or DataWindow JSON.

    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.

    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 JSON string to the DataStore.

    using DWNet.Data;
    using System;
    using System.IO;
    
    namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
    {
        public class ImportJsonByKeyExample
        {
            private readonly SchoolContext _context;
    
            public ImportJsonByKeyExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                // Gets the JSON file
                string path = Path.Combine(AppContext.BaseDirectory,
                                    @"Jsons\IDatastore\ImportJson1.json");
                string json = File.ReadAllText(path);
    
                // Imports data from JSON to DataStore
                datastore.ImportJsonByKey(json);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
    
                /*This code produces the following output:
    
                Rowcount: 2
               */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    JSON File: ImportJson1
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon