System.JSON.TJSONPathParser

De RAD Studio API Documentation
Aller à : navigation, rechercher

Delphi

TJSONPathParser = record

C++

struct DECLSPEC_DRECORD TJSONPathParser
{
public:
    enum class DECLSPEC_DENUM TToken : unsigned char { Undefined, Name, ArrayIndex, Eof, Error };
private:
    System::WideChar *FPathPtr;
    System::WideChar *FPtr;
    System::WideChar *FEndPtr;
    int FTokenArrayIndex;
    System::UnicodeString FTokenName;
    TToken FToken;
    bool __fastcall GetIsEof();
    void __fastcall RaiseError(System::PResStringRec AMsg);
    void __fastcall RaiseErrorFmt(System::PResStringRec AMsg, const System::TVarRec *AParams, const int AParams_High);
    void __fastcall ParseName();
    void __fastcall ParseQuotedName(System::WideChar AQuote);
    void __fastcall ParseArrayIndex();
    void __fastcall ParseIndexer();
    bool __fastcall EnsureLength(int ALength);
    void __fastcall FrontTrim(System::WideChar * &APtr);
    void __fastcall BackTrim(System::WideChar * &APtr);
public:
    __fastcall TJSONPathParser(const System::UnicodeString APath)/* overload */;
    __fastcall TJSONPathParser(const System::WideChar * APathPtr, int ALen)/* overload */;
    TToken __fastcall NextToken();
    __property bool IsEof = {read=GetIsEof};
    __property TToken Token = {read=FToken};
    __property System::UnicodeString TokenName = {read=FTokenName};
    __property int TokenArrayIndex = {read=FTokenArrayIndex};
    TJSONPathParser() {}
};

Propriétés

Type Visibilité  Source Unité  Parent
record
struct
public
System.JSON.pas
System.JSON.hpp
System.JSON System.JSON


Description

Analyseur d'un chemin JSON.

Un chemin JSON est une chaîne qui définit un chemin vers un élément spécifique avec des données JSON. Un chemin JSON est à JSON ce que XPath (EN) est à XML (EN).

Syntaxe de chemin JSON prise en charge

TJSONPathParser implémente un sous-ensemble de la spécification de chemin JSON définie par Stefan Göessner (EN). Spécifiquement, les éléments pris en charge sont :

  • Des opérateurs enfant pour les objets :
    • Utilisez . pour accéder aux propriétés d'objets dont le nom ne contient pas un point. Par exemple, utiliser root.child pour accéder à la propriété child de l'objet root.
    • Utilisez [] pour accéder aux propriétés d'objets dont le nom ne contient pas un caractère de délimitation. Par exemple, utilisez root['child.name'] ou root["child.name"] pour accéder à la propriété child.name de l'objet root.
  • Opérateur d'index ([]) pour les tableaux. Par exemple, utilisez root[0] pour accéder au premier élément du tableau root.

Ces opérateurs ne prennent pas en charge les expressions spéciales, ils prennent uniquement en charge les valeurs réelles (propriétés d'objets ou index de tableau).

Utilisation de TJSONPathParser

Lorsque vous créez une instance de TJSONPathParser, vous devez transmettre le chemin JSON cible au constructeur.

Lorsque vous avez une instance de TJSONPathParser, appelez NextToken pour parcourir les tokens du chemin JSON spécifié jusqu'à ce que IsEof vaille True ou que NextToken renvoie un token d'erreur.

Token contient le token renvoyé par le dernier appel à NextToken.

Pour un exemple de code qui montre comment utiliser TJSONPathParser, voir l'implémentation de TJSONIterator.Find.

Voir aussi