用户头像

178

2022-07-31

404

Create and Deserialize a JSON Array

The example below explains how to use activities such as Invoke Code and Deserialize Json Array to create a JSON array, deserialize it, and provide the list of extracted tokens. You can find these activities in the UiPath.WebAPI.Activities package.

此自动化流程的构建方法如下:

  1. 打开 Studio ,创建一个新“流程”。
  2. 将“序列”容器拖动至“工作流设计器”。
  3. 创建以下变量:
变量名称 变量类型 默认值
jsonAsString 字符串 -
jsonAsArray JArray -
  1. Add an Invoke Code activity inside the Sequence.
    • Click the Edit Code button and add the following code in the opened window:
Dim obj As ArrayList = New ArrayList() obj.Add("Starcraft") obj.Add("DOTA 2") obj.Add("FarCry") Out = JsonConvert.SerializeObject(obj)
  • Once the code is added, click the OK button.
  • Click the Edit Arguments button and add the following argument:
参数 方向 类型
out Out 字符串 jsonAsString
  • Once finished, select the OK button like in the below GIF:

10341034

  1. Add a Log Message activity below the Invoke Code activity.
    • Add the expression "JSON As String: "+jsonAsString in the Message field.
  2. Add a Deserialize Json Array activity below the Log Message activity.
    • Add the variable jsonAsString in the Json String field.
    • In the Properties panel, add the variable jsonAsArray in the JsonArray field.
  3. Add a For Each activity below the Deserialize Json Array activity.
    • Add the value token in the ForEach field.
    • Add the variable jsonAsArray in the VB expression field.
    • In the Properties panel, in the TypeArgument field, make sure you chose JValue.
  4. Add a Log Message activity inside the Body of the For Each activity.
    • Add the expression token.ToString in the Message field.

This is how the workflow should look:

545545

  1. Run the process. A JSON array is created, deserialized as a String and provided as a list of extracted tokens.

0条评论

用户头像
提交评论
RPA之家banner图