Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
prog:lazarus:classes:json [25/04/2021 14:09] thierry [Get] |
prog:lazarus:classes:json [01/05/2021 17:20] (Version actuelle) thierry [FindPath] |
||
---|---|---|---|
Ligne 20: | Ligne 20: | ||
===== Lire une valeur ===== | ===== Lire une valeur ===== | ||
- | ==== Get ==== | + | ==== TJSonObject.Get ==== |
''JSon.GET('Nom element', VALEUR PAR DEFAUT);''\\ | ''JSon.GET('Nom element', VALEUR PAR DEFAUT);''\\ | ||
Ligne 55: | Ligne 55: | ||
- Il permet de savoir quel **Get** on utilisera en fonction de son type.\\ Cela evite d'appeler le **Get** générique qui passe par les Variants | - Il permet de savoir quel **Get** on utilisera en fonction de son type.\\ Cela evite d'appeler le **Get** générique qui passe par les Variants | ||
</note> | </note> | ||
- | ==== FindPath ==== | + | ==== TJSonData.FindPath ==== |
- | Pour récuperer le JSONArray version dans le JSON suivant : | + | Pour récuperer le JSONArray ''version'' dans le JSON suivant : |
<code javascript> | <code javascript> | ||
{ | { | ||
Ligne 86: | Ligne 86: | ||
if assigned(vJD) then Result:=vJD.AsString; | if assigned(vJD) then Result:=vJD.AsString; | ||
</code> | </code> | ||
+ | ==== TJSonObject.Find (la sécurité) ==== | ||
+ | Dans l'exemple ci dessous on veut récupéré un eventuel JSonArray dans le JSonObject ''vJO''. | ||
+ | <code delphi> | ||
+ | var | ||
+ | vJO: TJSONObject; | ||
+ | vJA: TJSonArray; | ||
+ | vI: integer; | ||
+ | vS: string; | ||
+ | begin | ||
+ | ... | ||
+ | if vJO.Find('dependencies',vJA) then | ||
+ | for vI := 0 to vJA.Count - 1 do | ||
+ | vS:= vS+vJA.Strings[vI]; | ||
+ | ... | ||
+ | end; | ||
+ | </code> | ||
+ | ''TJsonObject.Find'' fonctionne avec tous ces types : | ||
+ | <code delphi> | ||
+ | Function Find(Const AName : String) : TJSONData; overload; | ||
+ | Function Find(Const AName : String; AType : TJSONType) : TJSONData; overload; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONData): boolean; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONObject): boolean; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONArray): boolean; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONString): boolean; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONBoolean): boolean; | ||
+ | function Find(const key: TJSONStringType; out AValue: TJSONNumber): boolean; | ||
+ | |||
+ | </code> | ||
+ | |||
====== Sources & Ressources ====== | ====== Sources & Ressources ====== |