当前位置:网站首页>delphi的json类:SuperObject,以及简单用法jsonHelper
delphi的json类:SuperObject,以及简单用法jsonHelper
2022-04-21 06:38:00 【海宏AA】
delphi的json类:SuperObject
转对象:
js:=so();
js.I['nID'] := nID; //
js.S['sKey'] := sKey; //
js.S['sID'] := sID; //
js.S['sID3'] := sID3; //
s:=sFtpPath; //路径
s:='/FTP'+iif(s='','/','')+s; //从FTP传的都要加这个
js.S['sPath'] := s; //FTP路径,FTP的都要加头/FTP/
js.S['sFile'] := extractFileName(sFile); //上传不带路径,路径在sFtpPath里
js.S['sFileOld']:= extractFileName(sFileOld);//
js.S['sImage'] := extractFileName(sImage); //
js.D['nSize'] := nSize; //
js.S['sExt'] := sExt; //
js.S['dDate'] := formatDateTime('yyyy-MM-dd hh:mm:ss',dDate);
s:=js.AsString();
取返回值:
vJson:=So(lowercase(sResult));
//检查结果
ret:=getJsonValue(vJson,'error','');
getJsonValue函数:
{*******************************json工具,20180101******************************
处理json的辅助类,zdj、zch,20180101
*******************************************************************************}
unit jsonHelper;
interface
uses
windows, sysUtils, superobject, variants;
function getJsonValue(json:ISuperObject; AField:string; ADefault:string=''):string; //获取json字段对应的值
implementation
uses untPub;
{
1.字段不存在时会报错;
2.字段区分大小写,故全部转换为小写
}
function getJsonValue(json: ISuperObject; aField, ADefault: string): string;
var v:variant;
function wuxiao:boolean;
begin
result:=variants.VarIsNull(v) or variants.VarIsType(v, varUnknown);
if not result then result:=v=ADefault;
end;
begin
result:=aDefault;
try
if (not assigned(json)) then exit;
v:=json.S[AField]; //lowercase(AField) dj180521不能转换大小写,因为有FTP密码
if wuxiao then v:=json.S[AField];
if wuxiao then v:=json.s[upperCase(AField)]; //oracle出来的全是大写
if wuxiao then v:=json.s[lowerCase(AField)];
if wuxiao then exit;
result:=variants.VarToStrDef(v, ADefault);
if (result='null') then result:=ADefault; //无效值
Except
on e:exception do untPub.writeErrorLogs('getJsonValue获取数据错误,字段-'+aField);
End;
end;
end.
文件下载地址:
https://download.csdn.net/download/gssystems/15397811
版权声明
本文为[海宏AA]所创,转载请带上原文链接,感谢
https://blog.csdn.net/gssystems/article/details/113914000
边栏推荐
- IPV4-IGP
- 论文阅读:Cached and Confused: Web Cache Deception in the wild
- 论文阅读:Supporting Early and Scalable Discovery of Disinformation Websites
- Dip image smoothing
- 设置谷歌浏览器深色黑色背景
- Nmap scanning and scapy projects
- Sorting method (3) = > quick sort and merge sort
- Three layer switch and router are connected to the Internet
- Sort method ----- > Hill sort, heap sort
- 【C#】LINQ
猜你喜欢
随机推荐
【C#】文件操作
leetcode 704·二分查找
TCP三次握手和四次挥手简介(2022.4.18-4.24)
Unable to infer base url. This is common when using dynamic servlet registration or when the API is
Implementation of crud of user management system with JDBC
論文閱讀:Measuring the Impact of a Successful DDoS Attack on the Customer Behaviour of Managed DNS Servi
论文阅读:Supporting Early and Scalable Discovery of Disinformation Websites
Outh2的基本概念
leetcode 59.螺旋矩阵Ⅱ
【网络协议】为什么要学习网络协议
2020-12-25
Using Wireshark to restore pcap data stream to picture file
MySQL common table structure
NP, NSSA area
关于数据治理平台中数据仓库ODS、DW和DM概念理解
2020-12-24
Financial information security training - 22 / 4 / 18
Blue Bridge Cup -- sequence sequencing problem
Solving 0 / 1 knapsack problem by dynamic programming
Defer









