corelibraries-devexpress-dot-dataaccess-dot-json-765725a2.md
Associates a JsonDataSource object with JSON data retrieved from a web service endpoint or a text file.
Namespace : DevExpress.DataAccess.Json
Assembly : DevExpress.DataAccess.v25.2.dll
NuGet Package : DevExpress.DataAccess
public class UriJsonSource :
JsonSourceBase
Public Class UriJsonSource
Inherits JsonSourceBase
You can add path parameters, query parameters, or header parameters to the UriJsonSource to customize requests to a JSON web service endpoint.
The following example demonstrates how to populate the JsonDataSource with data from a web-service endpoint.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
public static JsonDataSource CreateDataSourceFromWeb() {
var jsonDataSource = new JsonDataSource();
// Specify the endpoint.
jsonDataSource.JsonSource = new UriJsonSource(
new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
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("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))),
new JsonSchemaNode(new JsonNode("Address", false, JsonNodeType.Property, typeof(string)))
});
root.AddChildren(customers);
jsonDataSource.Schema = root;
// The schema is built, you do not have to call the Fill method to populate the Field List.
// The Designer calls the Fill method automatically when a document is generated for preview.
//jsonDataSource.Fill();
return jsonDataSource;
}
Imports System.Net
Imports DevExpress.DataAccess.Json
Imports DevExpress.XtraReports.UI
Public Shared Function CreateDataSourceFromWeb() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify the endpoint.
jsonDataSource.JsonSource = New UriJsonSource(
New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"))
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("CustomerID", True, JsonNodeType.Property,
GetType(String))) With {.DisplayName = "Customer ID"},
New JsonSchemaNode() With {.Name = "CompanyName", .Selected = True,
.NodeType = JsonNodeType.Property, .Type = GetType(String)},
New JsonSchemaNode(New JsonNode("ContactTitle", True, JsonNodeType.Property,
GetType(String))),
New JsonSchemaNode(New JsonNode("Address", False, JsonNodeType.Property,
GetType(String)))
})
root.AddChildren(customers)
jsonDataSource.Schema = root
' The schema is built, you do not have to call the Fill method to populate the Field List.
' The Designer calls the Fill method automatically when a document is generated for preview.
'jsonDataSource.Fill()
Return jsonDataSource
End Function
The following example demonstrates how to populate the JsonDataSource with JSON data from a file.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
public static JsonDataSource CreateDataSourceFromFile() {
var jsonDataSource = new JsonDataSource();
// Specify the JSON file name.
Uri fileUri = new Uri("customers.json", UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
// Populate the data source with data.
jsonDataSource.Fill();
return jsonDataSource;
}
Imports System.Net
Imports DevExpress.DataAccess.Json
Imports DevExpress.XtraReports.UI
Public Shared Function CreateDataSourceFromFile() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify the JSON file name.
Dim fileUri As New Uri("customers.json", UriKind.RelativeOrAbsolute)
jsonDataSource.JsonSource = New UriJsonSource(fileUri)
' Populate the data source with data.
jsonDataSource.Fill()
Return jsonDataSource
End Function
Object JsonSourceBase UriJsonSource
See Also