I’m getting started with DataAbstract/Delphi and I’m using the ROHttpApiDispatcher and a DAJSONDataStreamer to return the contents of a query as JSON. I’m wondering if there is a way to change the layout/format of the generated JSON.
Here is a quick sample using the methods that I’m using for reference:
vWhere := format('pk_id = %d', [AId]);
vDataSet := Connection.NewDataset('select * from test_table where ' + vWhere) as IDADataset;
vDataSet.LogicalName := 'foo';
vDataSet.Open;
Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_application_json_charset_utf8,'',false);
vJSON:=TDAJSONDataStreamer.Create(Self);
vJSON.Initialize(Result,aiwrite);
try
vJSON.WriteDataset(vDataSet, [woRows], -1);
finally
vJSON.Finalize;
end;
The resulting JSON is not what I was expecting. The result has a “fields” array, followed by a “rows” array:
{
"datasets": [
{
"name": "foo",
"data": {
"fields": [
{
"name": "FIELD_NAME_HERE"
},
.../snip/...
"rows": [
[
1,
.../snip/...
I get that this is more compact, as the field names are not repeated in each row of the data, but it is more difficult to read.
Is there an example using the this JSON to load into a TDataSet in delphi or c#?
Is there a way to change the layout of the JSON generated?
What I’m looking for is something more like this:
{
"datasets": [
{
"name": "foo",
"data": [
{
"Id": 1,
"Name": "Customers 1",
"Birth": "2014-01-22 14:05:03"
},
{
"Id": 2,
"Name": "Customers 2",
"Birth": "2014-01-22 14:05:03"
}
]
}
]
}
Thanks,
Leo