Back to Devexpress

JsonSchemaNode Class

corelibraries-devexpress-dot-dataaccess-dot-json-d9a0f6f0.md

latest5.5 KB
Original Source

JsonSchemaNode Class

Defines a node and its hierarchy in the JsonDataSource‘s schema.

Namespace : DevExpress.DataAccess.Json

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public class JsonSchemaNode :
    Node<JsonNode>,
    INotifyPropertyChanged
vb
Public Class JsonSchemaNode
    Inherits Node(Of JsonNode)
    Implements INotifyPropertyChanged

The following members return JsonSchemaNode objects:

LibraryRelated API Members
Cross-Platform Class LibraryDataSourceModel.JsonSchema
IJsonDataSourceModel.JsonSchema
JsonDataSource.LoadSchema(Type)
JsonDataSource.Schema
JsonDataSourceModel.JsonSchema
.NET Reporting ToolsXtraReportModel.JsonSchema

Remarks

A JsonDataSource‘s schema is a JsonSchemaNode class instance that represents the schema’s root node. The root node’s JsonSchemaNode.Children property contains a collection of JsonSchemaNode class instances that represent child nodes.

The following properties specify a schema node:

  • The Parent property specifies the node’s immediate parent.
  • The GetParents() method returns a collection of parent nodes up to the schema’s root level.
  • The Children property stores a collection of the node’s children. The AddChildren(Node<T>[]) method appends nodes to the Children collection.
  • The AbandonChildren() method removes all children from the node.
  • The Selected property specifies whether to allow users to select the node or its children as data source fields.
  • The Value property contains a JsonNode class instance that defines the node’s additional properties.

You can specify a hierarchy of JsonSchemaNode in the JsonDataSource.Schema collection before you call the JsonDataSource.Fill method. If you do not specify the schema, JsonDataSource.Fill creates the data source schema and populates the data source with the data.

Note

Set JsonDataSource.Schema to null before you call JsonDataSource.Fill to discard the previous schema changes.

Example

The code sample below defines the JSON data source schema that consists of the Customer ID and CompanyName fields.

csharp
using DevExpress.DataAccess.Json;
// ...
// Define the data source schema.
var root = new JsonSchemaNode();
root.NodeType = JsonNodeType.Object;
var customers = new JsonSchemaNode() { NodeType=JsonNodeType.Array, Name="Customers", Selected=true};
customers.AddChildren(new[] {
    new JsonSchemaNode(new JsonNode("ID", true, JsonNodeType.Property, typeof(string))) { DisplayName="Customer ID"},
    new JsonSchemaNode() { Name="CompanyName", Selected=true, NodeType=JsonNodeType.Property, Type=typeof(string)},
});
root.AddChildren(customers);
vb
Imports DevExpress.DataAccess.Json
' ...
' Define the data source schema.
Dim root = New JsonSchemaNode()
root.NodeType = JsonNodeType.Object
Dim customers = New JsonSchemaNode() With {.NodeType = JsonNodeType.Array, .Name = "Customers", .Selected = True}
customers.AddChildren({
    New JsonSchemaNode(New JsonNode("ID", True, JsonNodeType.Property, GetType(String))) With {.DisplayName = "Customer ID"},
    New JsonSchemaNode() With {.Name = "CompanyName", .Selected = True, .NodeType = JsonNodeType.Property, .Type = GetType(String)}
})
root.AddChildren(customers)

Inheritance

Object Node<JsonNode> JsonSchemaNode

See Also

JsonSchemaNode Members

Schema

DevExpress.DataAccess.Json Namespace