ObjectToJsonString首字母大写

ObjectToJsonString首字母大写,json,delphi,delphi-10-seattle,Json,Delphi,Delphi 10 Seattle,我使用的Web服务在字段名的大小写方面(在我看来)非常严格 我使用的是TJSON.ObjectToJsonString,它将所有字段名都小写。ObjectToJsonString环绕日期格式的所有选项,所以我有点不知所措 Delphi对象 TGeocodeServiceAddress = class(TInterfacedObject, IGeocodeServiceAddress) private FAbbreviationFormat: String; FCountryPostalF

我使用的Web服务在字段名的大小写方面(在我看来)非常严格

我使用的是TJSON.ObjectToJsonString,它将所有字段名都小写。ObjectToJsonString环绕日期格式的所有选项,所以我有点不知所措

Delphi对象

TGeocodeServiceAddress = class(TInterfacedObject, IGeocodeServiceAddress)
private
  FAbbreviationFormat: String;
  FCountryPostalFilter: String;
  FCountry: String;
  FCounty: String;
  FState: string;
  FCity: string;
  FStreetAddress: String;
  FZip : String;
public
  {getters and setters here. Edited for brevity}

  property Zip: String read GetZip write SetZip;
  property AbbreviationFormat: String read GetAbbreviationFormat write SetAbbreviationFormat;
  property CountryPostalFilter: String read GetCountryPostalFilter write SetCountryPostalFilter;
  property Country: String read GetCountry write SetCountry;
  property County: String read GetCounty write SetCounty;
  property State: string read GetState write SetState;
  property City: string read GetCity write SetCity;
  property StreetAddress: String read GetStreetAddress write SetStreetAddress;
end;
JSON字符串

{  
   "abbreviationFormat":"",
   "countryPostalFilter":"",
   "country":"USA",
   "county":"PIMA",
   "state":"AZ",
   "city":"TUCSON",
   "streetAddress":"6400 E. 6th St",
   "zip":"85711"
}


这是在
TJSONConverter.ConvertFieldNameToJson
方法中硬编码的。您可以通过字段属性提供自定义名称,也可以编写自己的转换器。好的,谢谢您提供的信息。对于将来的用户,TJSONConverter.ConvertFieldNameToJson位于REST.JsonReflect中unit@MartynA我认为这是一个坏主意,StringReplace将在整个Json上工作。有转换价值数据的风险。简单的自动替换永远不可信。@MartynA是的,你是对的,但我不希望它来自EmbarcaderoLike Victoria说,你可以使用该属性告诉转换器所需的字段命名。无需编写自定义转换器。例如:
[JSONName('AbbreviationFormat')]FAbbreviationFormat:String;[JSONName('CountryPostalFilter')]FCountryPostalFilter:String谢谢,注意到必须添加REST.Json.Types以使用子句才能使其工作
uses
...
  REST.Json.Types,
...

type
  CEItem= class
  public
    [JsonName('RowName')]
    RowName: String;
    [JsonName('Name')]
    Name: String;
    [JsonName('MaxStackSize')]
    MaxStackSize: FixedUInt;
    ...
  end;