Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#7

AW: JSON iterieren, aber wie?

  Alt 26. Sep 2022, 00:12
Die [] ist ein Delphi-Referenz durchsuchenTJSONArray,
und {} ein TJSONObject.

Über .P['abc'] kann man aber auch einen ganzen Pfad angeben (ähnlich dem Bei Google suchenXPath von XML)
Ich weiß, die Hilfe Delphi-Referenz durchsuchenTJSONObject.P ist wieder mal unterirdisch,
https://docwiki.embarcadero.com/Libr...N.TJSONValue.P
aber hier mal was aus den Sourcen.

https://docwiki.embarcadero.com/Libr...er#Description
Code:
  /// <summary> Parses a JSON path with names and indexes.</summary>
  /// <remarks>
  ///  The syntax to write paths is similar to XPath but in a Json way.
  ///  The following XPath expression:
  ///    /entities/urls[0]/indices[1]
  ///  would look like
  ///    entities.urls[0].indices[1]  (dot notation)
  ///  or
  ///    entities["urls"][0]["indices"][1]  (bracket notation)
  ///
  ///  The dot (.) token is used to access the object elements:
  ///    ex: object.key
  ///
  ///  The bracket ([]) token is used to access array or object elements:
  ///    In array: cities[0]
  ///    In object: city["name"] or city['name']
  ///    In object: ["city"]["name"] or ['city']['name']
  ///
  ///  The quote (" or ') is used to introduce a literal when the element is being written in bracket notation:
  ///    ex:["first"]["second"] or ['first']['second']
  ///
  ///  To escape the quote in a literal use backslash (\): \"
  ///    ex: ["quotes(\").should.be.escaped"] or ['quotes(\').should.be.escaped']
  ///
  ///  Note: The backslash will only escape quotes within a literal. Bracket notation can be useful when
  ///  names can not be written in dot notation, like the objects keys with dot characters:
  ///    ex: object["key.with.dots"] or object['key.with.dots']
  ///
  /// </remarks>
  TJSONPathParser = record
$2B or not $2B

Geändert von himitsu (26. Sep 2022 um 00:16 Uhr)
  Mit Zitat antworten Zitat