REST.Json.TJson.ObjectToJsonString

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class function ObjectToJsonString(AObject: TObject; AOptions: TJsonOptions = [joDateIsUTC, joDateFormatISO8601]): string;

C++

__classmethod System::UnicodeString __fastcall ObjectToJsonString(System::TObject* AObject, TJsonOptions AOptions = (TJsonOptions() << TJsonOption::joDateIsUTC << TJsonOption::joDateFormatISO8601 ));

Properties

Type Visibility Source Unit Parent
function public
REST.Json.pas
REST.Json.hpp
REST.Json TJson

Description

Returns a JSON string that represents the specified TObject descendant.

JSON Options

ObjectToJsonString accepts an optional set of options, AJsonOptions, that determines how ObjectToJsonString interprets the data of AObject and renders that data in the resulting JSON string.

The table below describes all the available JSON options that you may specify. ObjectToJsonString uses joDateIsUTC and joDateFormatISO8601 if you do not specify a custom value for AJsonOptions.

Option Description

joDateFormatISO8601

Formats dates using the ISO 8601 standard. For example: "2014-12-01T13:14:18Z" (Mon, 01 Dec 2014 13:14:18 UTC).

joDateFormatMongo

Formats dates as MongoDB Extended JSON. For example: { "$date": "2014-12-01T13:14:18.000+00:00" } (Mon, 01 Dec 2014 13:14:18 UTC).

joDateFormatUnix

Formats dates as Unix time. For example: "1417439658" (Mon, 01 Dec 2014 13:14:18 UTC).

joDateIsUTC

Times in AObject use the UTC time standard.

If you do not specify this option, ObjectToJsonString assumes that times in AObject use the local timezone of your system.

joIgnoreEmptyArrays

Does not include key-value pairs of JSON objects when the value of a pair would be an empty JSON array.

For example, if AObject can be serialized using JSON as { "key1": [], "key2": "value2" }, the joIgnoreEmptyArrays option makes the resulting JSON code { "key2": "value2" } instead.

joIgnoreEmptyStrings

Does not include key-value pairs of JSON objects when the value of a pair is an empty string.

For example, if AObject can be serialized using JSON as { "key1": "value1", "key2": "" }, the joIgnoreEmptyStrings option makes the resulting JSON code { "key1": "value1" } instead.

See Also