将 Json 字符串转换为我自己的对象时遇到一些问题。我举一些例子:
我的课:
TClasse = class
private
Fid: integer;
Fnome: string;
procedure Setid(const Value: integer);
procedure SetNome(const Value: string);
published
property id : integer read Fid write Setid;
property nome : string read Fnome write SetNome;
end;
implementation
procedure TClasse.SetNome(const Value: string);
begin
Fnome := Value;
Fnome := 'testing: '+Fnome;
end;
我用这个方法:
cl := TJSON.JsonToObject<TClasse>('{ "id" : 12, "nome" : "abc" }');
这意味着当执行“JsonToObject”方法时,他将实例化我的类并通过设置器将值设置为 then。属性“nome”应该具有值“testing: abc”,但它只有 json 中的“abc”部分。调试也不通过设置器。
难道我做错了什么?
您可以创建一个新课程,例如TJSON_Respond帮助序列化
TJSON_Respond= class
public
[JSONName('id')] id: Integer;
[JSONName('nome')] nome: String;
end;
cl := TJson.JSONToObject<TJSON_Respond>('{ "id" : 12, "nome" : "abc" }');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)