JsonSchemaNode Class
Defines a node and its child nodes in the JsonDataSource‘s schema.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v18.2.dll
Declaration
Related API Members
The following members return JsonSchemaNode objects:
Library | Related API Members |
---|---|
Cross-Platform Class Library | DataSourceModel.JsonSchema |
IJsonDataSourceModel.JsonSchema | |
JsonDataSource.Schema | |
JsonDataSourceModel.JsonSchema | |
Reporting | XtraReportModel.JsonSchema |
Remarks
The JsonDataSource‘s schema nodes are defined by the JsonNode class. However, if a schema node has a collection of child nodes, it is defined by the JsonSchemaNode class. This class has a reference to the JsonNode object and members that define a child node collection.
Use the AddChildren(Node<T>[]) method to populate the JsonSchemaNode‘s child collection. The following code sample demonstrates how to do this.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
//...
private JsonDataSource CreateDataSourceFromWeb()
{
var jsonDataSource = new JsonDataSource();
//Specify the data source location
jsonDataSource.JsonSource = new UriJsonSource(new Uri("http://northwind.servicestack.net/customers.json"));
// Define the Customers node's scheme to retrieve only required child nodes and properties
var customers = new JsonSchemaNode() {NodeType=JsonNodeType.Array, Name="Customers", Selected=true };
customers.AddChildren(new[] {
new JsonSchemaNode(new JsonNode("CustomerID", true, JsonNodeType.Property, typeof(string))) { DisplayName = "Customer ID" },
new JsonSchemaNode() {
Name = "CompanyName",
Selected = true,
NodeType = JsonNodeType.Property,
Type = typeof(string)
},
new JsonSchemaNode(new JsonNode("ContactTitle", true, JsonNodeType.Property, typeof(string))),
//Set the JsonNode.Selected to false not to retrieve the Address field
new JsonSchemaNode(new JsonNode("Address", false, JsonNodeType.Property, typeof(string)))
});
// Create a root schema node
var root = new JsonSchemaNode();
root.NodeType = JsonNodeType.Object;
// Add the defined Customers schema node to the root node
root.AddChildren(customers);
// Specify the JsonDataSource's Scheme property to retrieve data only from the Customers node
jsonDataSource.Schema = root;
// Retrieve data from the JSON data source
jsonDataSource.Fill();
return jsonDataSource;
}
See Also