- Überblick
- Kryptografie
- Datenbank
- Java
- Python
- WebAPI
- Versionshinweise
- Über das WebAPI-Aktivitätspaket
- Projektkompatibilität
- XML deserialisieren (Deserialize XML)
- XPath ausführen (Execute XPath)
- XML-Knotenattribute erhalten (Get XML Node Attributes)
- XML-Knoten erhalten (Get XML Nodes)
- JSON serialisieren
- Deserialize JSON
- JSON-Zusammenstellung deserialisieren (Deserialize Json Array)
- HTTP Request (legacy)
- HTTP-Anfrage (HTTP Request)
- SOAP-Anfrage (SOAP Request)
Entwickleraktivitäten
UiPath.WebAPI.Activities.DeserializeJson
Beschreibung
Deserializes the JSON string or sample to a JSON object. By default, the result is a JObject, but you can choose a different output type using the Output type property.
Projektkompatibilität
Windows - Legacy | Windows | Plattformübergreifend
Voraussetzungen
To configure the Serializer settings property using data mapping, use Studio 25.10 or later. In earlier Studio versions, this property uses the Expression Editor window instead.
Windows, plattformübergreifende Konfiguration
- JSON String - The string containing the JSON to be deserialized. The JSON should be written without indents, and between double quotes. Strings inside the JSON should be written with single quotes. For example, the following JSON is valid: "{'TenancyName': 'Documentation', 'UsernameOrEmail': 'Documentation', 'Password': 'Documentation'}".
- JSON Sample - A sample of the JSON used to generate the output object properties. The sample must be in JSON format. The activity converts this sample into a similar object that you can use during design time.
Erweiterte Optionen
Eingabe
- Serializer settings - Custom deserializer settings to be used when deserializing the JSON string. Use this property when you want to fully control how the JSON string is deserialized.
- Output type - A drop-down list that lets you choose the argument type of the object to deserialize into.
Hinweis:
In Studio Web, generating the output structure from the JSON Sample property makes the Output type property read-only.
Ausgabe
- JSON object - The deserialized JSON, returned as an object of the type selected in the Output type property. When the default type is used, the result is a
Newtonsoft.Json.Linq.JObjectvariable. Read more information onNewtonsoft.Json.Linq.JObjectobjects.
Example of using the JSON Sample
The JSON Sample property generates the output object structure at design time from a representative JSON snippet. After you provide a sample, the activity infers a matching type and assigns it to the Output type property, so you can reference the deserialized values by name in downstream activities instead of querying them with SelectToken.
The JSON Sample property is a design-time helper. It is available in Studio Web and in Studio versions that support custom type inference. When these features are not available, the property is hidden.
To exemplify how to use the JSON Sample, we extract a person's name and city from a JSON string:
-
Add a Deserialize JSON activity to your workflow.
-
In the JSON String field, enter the JSON to deserialize. For example:
"{'name': 'John Doe', 'age': 30, 'address': {'city': 'New York'}}". -
In the JSON Sample field, paste a representative sample with the same structure:
{ "name": "John Doe", "age": 30, "address": { "city": "New York" } }{ "name": "John Doe", "age": 30, "address": { "city": "New York" } }The activity reads the sample and generates an output object that mirrors this structure. The Output type property updates to the generated type.
-
In a subsequent activity, reference the deserialized values directly through the property names defined in your sample, for example
JsonObject.nameandJsonObject.address.city, instead of usingJsonObject.SelectToken("name").
Ergebnis
The output object exposes the properties from your sample, so JsonObject.name returns John Doe and JsonObject.address.city returns New York without querying the JSON with SelectToken.
Example of using Serializer settings
When no data mapping is available for the Serializer settings property, configure it in the Expression Editor using one of the following code snippets. For more information, see the Newtonsoft documentation.
VB.NET
New JsonDeserializationSettings With {
.MissingMemberHandling = JsonMissingMemberHandling.Ignore,
.NullValueHandling = JsonNullValueHandling.Ignore,
.DateParseHandling = JsonDateParseHandling.DateTime,
.DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
.FloatParseHandling = JsonFloatParseHandling.Double
}
New JsonDeserializationSettings With {
.MissingMemberHandling = JsonMissingMemberHandling.Ignore,
.NullValueHandling = JsonNullValueHandling.Ignore,
.DateParseHandling = JsonDateParseHandling.DateTime,
.DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
.FloatParseHandling = JsonFloatParseHandling.Double
}
C#
new JsonDeserializationSettings
{
MissingMemberHandling = JsonMissingMemberHandling.Ignore,
NullValueHandling = JsonNullValueHandling.Ignore,
DateParseHandling = JsonDateParseHandling.DateTime,
DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
FloatParseHandling = JsonFloatParseHandling.Double
}
new JsonDeserializationSettings
{
MissingMemberHandling = JsonMissingMemberHandling.Ignore,
NullValueHandling = JsonNullValueHandling.Ignore,
DateParseHandling = JsonDateParseHandling.DateTime,
DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
FloatParseHandling = JsonFloatParseHandling.Double
}
Windows – Legacy-Konfiguration
Eigenschaften-Panel
Allgemein
- AnzeigeName (DisplayName) - Der Anzeigename der Aktivität.
Eingabe
- JSON Sample - The JSON sample for the output structure. The activity converts this sample into a similar object which you can use during design time.
- JsonZeichenfolge - Die Zeichenfolge, die das zu deserialisierende JSON enthält. Schreiben Sie das JSON ohne Einrückungen und in doppelte Anführungszeichen. Zeichenfolgen innerhalb des JSON-Objekts müssen in einfachen Anführungszeichen geschrieben werden. Zum Beispiel ist das folgende JSON-Objekt gültig: „{'TenancyName': 'Documentation', 'UsernameOrEmail': 'Documentation', 'Password': 'Documentation'}“.
Sonstiges
- Privat (Private) - Bei Auswahl werden die Werte von Variablen und Argumenten nicht mehr auf der Stufe Verbose protokolliert.
- Argumenttyp – Eine Dropdownliste, mit der Sie den Typ der zurückgegebenen Ausgabe auswählen können. Die angegebene JSON-Zeichenfolge wird in ein Objekt des ausgewählten Typs konvertiert.
Ausgabe
- JsonObject - The deserialized JSON, as a
Newtonsoft.Json.Linq.JObjectvariable. Read more information onNewtonsoft.Json.Linq.JObjectobjects.
Beispiel für die Verwendung der Aktivität Deserialize Json
Die Aktivität Deserialize Json wird zum Extrahieren von Daten aus JSON-Dateien und -Zeichenfolgen verwendet.
Um die Verwendung dieser Aktivität zu veranschaulichen, haben wir ein Beispiel erstellt, das die Aktivität Deserialize Json verwendet, um das Alter einer Person aus einer JSON-Datei zu extrahieren.
So kann der Automatisierungsprozess erstellt werden:
- Öffnen Sie Studio und erstellen Sie einen neuen Prozess.
- Drag a Sequence to the Workflow Designer.
-
Erstellen Sie die folgenden Variablen:
Variablenname Variablentyp Standardwert JsonTextString JsonObjJObject AgeGenericValue
-
- Drag a Read Text File activity inside the sequence container.
- In the Properties panel, add the value
"JsonString.txt"in the FileName field. - Add the variable
JsonTextin the Content field.
- In the Properties panel, add the value
- Fügen Sie die Aktivität Deserialize JSON nach der Aktivität Read Text File hinzu.
- In the Properties panel, add the variable
JsonTextin the JsonString field and the variableJsonObjin the JsonObject field. - Select the value
Newtonsoft.Json.Linq.JObjectfrom the TypeArgument drop-down list.
- In the Properties panel, add the variable
- Place an Assign activity under the Deserialize JSON activity.
- Add the variable
Agein the To field and the expressionJsonObj.SelectToken("age").ToStringin the Value field.
- Add the variable
- Ziehen Sie eine Write Line-Aktivität nach der Assign-Aktivität.
- Fügen Sie die Variable
Agein das Feld Text ein.
- Fügen Sie die Variable
- Run the process. The robot extracts the age value from the
.jsonfile and displays it in the Output panel.
Hier können Sie ein Beispiel herunterladen.
- Beschreibung
- Projektkompatibilität
- Voraussetzungen
- Windows, plattformübergreifende Konfiguration
- Erweiterte Optionen
- Example of using the JSON Sample
- Ergebnis
- Example of using Serializer settings
- VB.NET
- C#
- Windows – Legacy-Konfiguration
- Eigenschaften-Panel
- Beispiel für die Verwendung der Aktivität Deserialize Json