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

相关阅读 >>

Delphi 7 中的随机函数

Delphi 截取被遮挡的window画面

Delphi xmldocument控件之xml

Delphi 获取窗体坐标触发事件

Delphi修改资源文件的代码

Delphi 生成全球唯一标识符

Delphi双击tmemo选择光标所在行

Delphi 声明指令 调用左右

Delphi tfilestream 的读写 合并文件

Delphi+sql数据库增加,删除,修改,查询操作

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...