delphi10.2.3解决的一个JSON问题  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi10.2.3解决的一个JSON问题


发现在Delphi 10.1.2上,下面的代码生成的JSON串不对:
procedure TForm2.btn1Click(Sender: TObject);
var
  jo:TJSONObject;
  s:string;
begin
  jo:=TJSONObject.Create;
  jo.AddPair('test','');
  s:=jo.ToJSON;
  ShowMessage(s);
end;
换到Delphi 10.2.3下,则正常输出:
'{"test":""}'

查看代码,发现10.2.3是这样实现的:
function TJSONObject.AddPair(const Str: string; const Val: string): TJSONObject;
begin
  if (not Str.IsEmpty) then
    AddPair(TJSONPair.Create(Str, Val));
  Result := Self;
end;
而10.1.2是这样实现的:
function TJSONObject.AddPair(const Str: string; const Val: string): TJSONObject;
begin
  if (not Str.IsEmpty) and (not Val.IsEmpty) then
    AddPair(TJSONPair.Create(Str, Val));
  Result := Self;
end;

明显是10.1.2的bug,还好在新版本中修正了!

http://blog.sina.com.cn/s/blog_44fa172f0102x3i5.html

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043668031692505 seconds