JsonDataSource.JsonSource Property
Gets or sets an object that stores JSON data import settings.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v19.1.dll
Declaration
[DefaultValue(null)]
[LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)]
public JsonSourceBase JsonSource { get; set; }
Property Value
Type | Default | Description |
---|---|---|
JsonSourceBase | *null* | A JsonSourceBase descendant that specifies the JSON data location. |
Remarks
Use the JsonSource property to specify the JSON-formatted data location. Set the JsonSource property to a JsonSourceBase descendant.
JSON Data Location | JsonSource Property Value |
---|---|
Web-service endpoint | A UriJsonSource object |
Text file | A UriJsonSource object |
JSON string | A CustomJsonSource object |
Examples
The code sample below illustrates how to use JSON data from the Web.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
// ...
public static JsonDataSource CreateDataSourceFromWeb() {
var jsonDataSource = new JsonDataSource();
// Specify the data source location
jsonDataSource.JsonSource = new UriJsonSource(new Uri("http://northwind.servicestack.net/customers.json"));
// Retrieve data from the JSON data source to the Report Designer's Field List
jsonDataSource.Fill();
return jsonDataSource;
}
The code sample below illustrates how to use JSON data from a file.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
public static JsonDataSource CreateDataSourceFromFile() {
var jsonDataSource = new JsonDataSource();
// Specify the a JSON file's name
Uri fileUri = new Uri("customers.json", UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
// Retrieve data from the JSON data source to the Report Designer's Field List
jsonDataSource.Fill();
return jsonDataSource;
}
The code sample below illustrates how to use JSON data from a string variable.
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
public static JsonDataSource CreateDataSourceFromText() {
var jsonDataSource = new JsonDataSource();
// Specify a string with JSON content
string json = "{\"Customers\":[{\"Id\":\"ALFKI\",\"CompanyName\":\"Alfreds Futterkiste\",\"ContactName\":\"Maria Anders\",\"ContactTitle\":\"Sales Representative\",\"Address\":\"Obere Str. 57\",\"City\":\"Berlin\",\"PostalCode\":\"12209\",\"Country\":\"Germany\",\"Phone\":\"030-0074321\",\"Fax\":\"030-0076545\"}],\"ResponseStatus\":{}}";
// Specify the object that retrieves JSON data
jsonDataSource.JsonSource = new CustomJsonSource(json);
// Retrieve data from the JSON data source to the Report Designer's Field List
jsonDataSource.Fill();
return jsonDataSource;
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the JsonSource property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.