導航:首頁 > 編程語言 > 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例子相關的資料

熱點內容
蘋果facebook錯誤代碼0 瀏覽:466
cad宋體字型檔文件 瀏覽:747
蘋果手機中的文件怎麼導入電腦 瀏覽:656
如何不讓刪除文件 瀏覽:749
word插入智能卡 瀏覽:276
電腦上怎麼掃描圖片發成文件 瀏覽:894
證件照列印時保存成什麼類型文件 瀏覽:819
耐克阿迪什麼網站 瀏覽:967
led一般用的什麼app 瀏覽:271
8歲小孩如何學會編程 瀏覽:604
文件袋大小的電腦是多少寸 瀏覽:153
swag網站怎麼沒有了 瀏覽:143
下載的文件解壓密碼是多少 瀏覽:294
磁碟文件系統空白 瀏覽:737
ae氣功特效教程 瀏覽:727
紙飛機網站是什麼 瀏覽:742
文件系統錯誤65535 瀏覽:644
迅雷沒下載完的文件怎麼打開 瀏覽:878
delphijson例子 瀏覽:180
js放在jsp中不生效 瀏覽:674

友情鏈接