导航:首页 > 编程语言 > delphijson例子

delphijson例子

发布时间:2025-08-17 15:20:57

❶ delphi怎么得到下面的json数据中的多个节点值

Delphi下解析json可以去下载一个superobject单元,关于这个单元的使用可以网络一下,很好用的

Delphi/Pascal code?

// Sample 2: how to get child type and subobject fields
//
// Leonid Koninin, 02/03/2007
program sample2;
{$APPTYPE CONSOLE}
uses SysUtils, uLkJSON in 'uLkJSON.pas';
var JSon, XJSon :TlkJSONobject; JSonNode :TlkJSONString; JSonNodeList :TlkJSONlist; Str :String; i :Integer;
begin
Str := '{"string1":"one", "string2":"two", '
+'"childobject" : {"objstr1" :"Oone", "objstr2" :"Otwo"},'
+'"childobject2":[{"obj2str1":"2one"},{"obj2str1":"2two"}]}'; writeln(Str);

JSon := TlkJSON.ParseText(Str) as TlkJSONobject; // restore object (parse text)

if not assigned(JSon) then begin // how to obtain type of child
writeln('error: xs not assigned!'); readln; //exit;
end else begin //Field[] is 方式判断类型
if JSon.Field['childobject'] is TlkJSONString then writeln('type: xs is string!'); //string
if JSon.Field['childobject'] is TlkJSONlist then writeln('type: xs is list!'); //list 多个Json子节点
if JSon.Field['childobject'] is TlkJSONobject then writeln('type: xs is object!'); //Oject 单个json子节点

//以下类型,实际不常用
if JSon.Field['childobject'] is TlkJSONnumber then writeln('type: xs is number!'); //数字 value前后不加引号
if JSon.Field['childobject'] is TlkJSONboolean then writeln('type: xs is boolean!'); //boolean
if JSon.Field['childobject'] is TlkJSONnull then writeln('type: xs is null!'); //Null 改为空格值
end;

//Filed[].SelfType 方式判断类型
case JSon.Field['childobject'].SelfType of //the other way (0.93+)
jsString :writeln('other type: xs is string');
jsObject :writeln('other type: xs is object');
jsList :writeln('other type: xs is list');

jsNumber :writeln('other type: xs is number');
jsBoolean :writeln('other type: xs is boolean');
jsNull :writeln('other type: xs is null');
jsBase :writeln('other type: xs is base');
end;
writeln('self-type name: ', JSon.Field['childobject'].SelfTypeName);

XJSon :=JSon.Field['childobject'] as TlkJSONobject; //JSON中,有下级节点的,不像xml那样称为节点对象,仍称为JSOn对象

//Field[] as方式取值,完美
JSonNode :=XJSon.Field['objstr1'] as TlkJSONString; //we know what xs chilren are strings
writeln(JSonNode.value);

JSonNode :=XJSon.Field['objstr2'] as TlkJSONstring;
writeln(JSonNode.value);

//getstring,快速
writeln(XJSon.getString('objstr1')); //new v0.99 +syntax!
writeln(XJSon.getString('objstr2')); readln;

JSon.Free;
end.

阅读全文

与delphijson例子相关的资料

热点内容
特斯拉中国数据中心在哪里建设 浏览:417
今日头条下载视频存在哪个文件夹 浏览:652
淘宝开源java 浏览:514
阅读的书源在哪个文件夹 浏览:136
怎么去掉超链接的网站 浏览:90
app不再获取用户信息会怎么样 浏览:399
机器扫描文件多少钱 浏览:379
javasocket网络编程 浏览:904
为什么数据流量上有个e 浏览:610
锤子手机桌面文件夹 浏览:613
ps吸管工具视频教程 浏览:636
苹果facebook错误代码0 浏览:466
cad宋体字库文件 浏览:747
苹果手机中的文件怎么导入电脑 浏览:656
如何不让删除文件 浏览:749
word插入智能卡 浏览:276
电脑上怎么扫描图片发成文件 浏览:894
证件照打印时保存成什么类型文件 浏览:819
耐克阿迪什么网站 浏览:967
led一般用的什么app 浏览:271

友情链接