JsonArrayGetObject

value JsonArrayGetObject ( value jsonArray, value Index );

Rückgabewert

Rückgabewert

Beschreibung

JSONARRAY-Objekt

Das neu erstellte JSON-Objekt, das mit den JSON-Daten des Elements im JSONARRAY-Objekt jsonArray geladen wurde.

FALSE / false / 0

Das Auslesen des JSON-Elements ist fehlgeschlagen. Es wurde kein Element an der Position Index gefunden bzw. das Element an der Position ist kein JSON-Element.

Parameter

jsonArray

Das JSONARRAY-Objekt, von dem ein JSON-Element ausgelesen werden soll.

Index

Die Position des JSON-Elements, das aus dem JSONARRAY-Objekt jsonArray ausgelesen werden soll. Für das erste JSONARRAY-Element gilt: Index = 0.

Bemerkungen

Erzeugt ein JSON-Objekt, das mit dem Inhalt des JSON-Elements geladen wird, das sich an der Position Index im JSONARRAY-Objekt jsonArray befindet. Wird das JSON-Objekt nicht mehr benötigt, so sollte mit JsonClose zerstört werden.

Das zugelieferte JSON-Objekt (hier jsonResult genannt) ist ein Referenzobjekt zum JSON-Objekt (hier jsonFound genannt) das im JSONARRAY-Objekt jsonArray gefunden wurde. Das bedeutet, jede Änderung am JSON-Objekt jsonResult wirkt sich direkt auf das JSON-Objekt jsonFound im JSONARRAY-Objekt jsonArray aus. Wird das JSON-Objekt jsonResult mit JsonArrayClose geschlossen, so hat dies keine Auswirkung auf das JSON-Objekt jsonFound im JSONARRAY-Objekt jsonArray.

Beim Beenden eines laufenden Projekts schließt Victory automatisch alle nicht geschlossenen JSON/JSONARRAY-Objekte, wird z.B. ein JSON-Objekt mit JsonArrayGetObject im _InitApplication erzeugt und dieses dann dauerhaft verwendet, so muss dieses nicht explizit im _ExitApplication geschlossen werden.

Beispiel

//Inhalt von Datei "Produktliste.json":
//{
//  "Produktliste": {
//    "Produktgruppe": "PVC-isolierte Starkstromkabel 0,6/1kV",
//    "Produkt": [
//      {
//        "Type": "E-YY 4 x 6 RE",
//        "Aderanzahl": 4,
//        "Aussendurchmesser": 15,
//        "Belastbarkeit (Erde)": 59,
//        "Belastbarkeit (Luft)": 43,
//        "Verfügbar": true
//      },
//      {
//        "Type": "E-YY 1 x 16 RE",
//        "Aderanzahl": 1,
//        "Aussendurchmesser": 11,
//        "Belastbarkeit (Erde)": 107,
//        "Belastbarkeit (Luft)": 84,
//        "Verfügbar": false
//      }
//    ]
//  }
//}
value json;
if (!JsonCreateFromFile(json, "Produktliste.json"))
    return (false);
end
value products;
products = JsonGetArray(json, "Produktliste.Produkt");

value product;
product = JsonArrayGetObject(products, 0);

//following function call has the same result
//product = JsonArrayGetObject(json, "Produktliste.Produkt[0]"); string strJson;
strJson = JsonToString(product);
//Inhalt von strJson:
//{
//  "Type": "E-YY 4 x 6 RE",
//  "Aderanzahl": 4,
//  "Aussendurchmesser": 15,
//  "Belastbarkeit (Erde)": 59,
//  "Belastbarkeit (Luft)": 43,
//  "Verfügbar": true
//}
JsonClose(json);
 

Die Json-Funktionen

Siehe auch JsonArrayGetArray, JsonArrayGetBool, JsonArrayGetNumber, JsonArrayGetSize, JsonArrayGetString, JsonArrayGetType, JsonArrayIsNull