![]() |
einfaches JSON Beispiel
Hallo zusammen,
stehe mit JSON auf dem Kriegsuß, kann mir jemand bitte ein simples Beispiel für die Abfrage vom 2. "status" Feld geben? danke vorab!
Code:
danke!:thumb:
{"status":"success","data":{"status":"online","benchmarking":"TEST","online":"connected"}}
|
AW: einfaches JSON Beispiel
Ohne jede Fehlerbehandlung:
Delphi-Quellcode:
uses System.JSON;
const _JSON = '{"status":"success","data":{"status":"online","benchmarking":"TEST","online":"connected"}}'; procedure TFormTest.btnTestClick(Sender: TObject); var lOuterObj: TJSONObject; lInnerObj: TJSONObject; begin lOuterObj := TJSONObject.ParseJSONValue(_JSON) as TJSONObject; try lInnerObj := lOuterObj.Values['data'] as TJSONObject; ShowMessage(lInnerObj.Values['status'].Value); finally lOuterObj.Free; end; end; |
AW: einfaches JSON Beispiel
Alternative:
Delphi-Quellcode:
program Project1;
{$R *.res} uses System.SysUtils, System.JSON; const input = '{"status":"success","data":{"status":"online","benchmarking":"TEST","online":"connected"}}'; var jsonObj: TJsonObject; status: String; begin jsonObj := TJSONObject.ParseJSONValue(input) as TJsonObject; if(not Assigned(jsonObj)) then WriteLn('input is no valid json object') else try status := jsonObj.GetValue<String>('data.status'); WriteLn('status is ', status); finally jsonObj.Destroy(); end; end. |
AW: einfaches JSON Beispiel
Zitat:
ahhh, das "data.status" hatte ich nicht so.... Danke an beide! So langsam begreife ich es mal... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz