#1 2017-09-05 02:07:33

linbren
Member
Registered: 2017-08-11
Posts: 42

use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

procedure TfmlJson.btnO2JClick(Sender: TObject);
var
  TestObj:TMyTest;
  s:RawUTF8;
begin
  TestObj:=TMyTest.Create;
  TestObj.ITEM_ID:=1;
  TestObj.ITEM_NAME:='mainItem';
  TestObj.MyDate:=Now;
  TestObj.AddChild(11,'subItem11');
  TestObj.AddChild(12,'subItem12');
  Memo1.Lines.Add( ObjectToJSON(TestObj,[woHumanReadable,woDontStoreDefault,woObjectListWontStoreClassName]));
  TestObj.Free;
end;
==================
{
	"ChildList": 
	[{
			"CHILD_ID": 11,
			"CHILD_NAME": "subItem11"
		},{
			"CHILD_ID": 12,
			"CHILD_NAME": "subItem12"
		}
	],
	"ITEM_ID": 1,
	"ITEM_NAME": "mainItem",
	"MyDate": "2017-09-05T10:03:14"
}
{
	"ChildList": 
	[{
			"CHILD_ID": 11,
			"CHILD_NAME": "subItem11"
		},{
			"CHILD_ID": 12,
			"CHILD_NAME": "subItem12"
		}
	],
	"ITEM_ID": 1,
	"ITEM_NAME": "mainItem",
	"MyDate": "2017-09-05T10:03:34"
}
{
	"ChildList": 
	[{
			"CHILD_ID": 11,
			"CHILD_NAME": "subItem11"
		},{
			"CHILD_ID": 12,
			"CHILD_NAME": "subItem12"
		}
	],
	"ITEM_ID": 1,
	"ITEM_NAME": "mainItem",
	"MyDate": "2017-09-05T10:03:35"
}
{
	"ChildList": 
	[{
			"CHILD_ID": 11,
			"CHILD_NAME": "subItem11"
		},{
			"CHILD_ID": 12,
			"CHILD_NAME": "subItem12"
		}
	],
	"ITEM_ID": 1,
	"ITEM_NAME": "mainItem",
	"MyDate": "2017-09-05T10:03:35"
}

===="MyDate": "2017-09-05T10:03:35"
here 'T' in the middle. what happen ?

Last edited by linbren (2017-09-07 08:37:21)


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#2 2017-09-05 07:03:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,274
Website

Re: use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

Please follow the forum rules.
https://synopse.info/forum/misc.php?action=rules
Don't post such extensive source code in the forum.

About your question, the framework generates valid ISO-8601 timestamp text.
It includes a 'T' by standard.

Online

#3 2017-09-05 07:18:57

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

sorry for break the rule .

while i don't need the 'T' here, how to avoid it ?


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#4 2017-09-05 07:43:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,274
Website

Re: use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

Then store your field as plain RawUTF8 text...
A ISO-8601 text should match the standard.

Online

#5 2017-09-06 00:26:52

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

I'd like to have one more option such like [woDateTimeSimple] .
they are many conveniences  while there are fields defined as TDATETIME in database .


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#6 2017-09-06 06:09:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,274
Website

Re: use ObjectToJSON convert TDATETIME to json , get a 'T' char in string

Adding an option to generate non standard date time does not make sense at all.
What is your problem with the "T" character?
The JSON should use standard encoding, i.e. proper ISO-8601. JSON is used to transmit values per representation - not for presentation.
It is up to the client application to convert it back to TDateTime value, then display it as expected, with the display format as expected by the end user locale.

Online

Board footer

Powered by FluxBB