UiPath Documentation
activities
latest
false

开发者活动

上次更新日期 2026年4月21日

创建和反序列化 JSON 数组

以下示例说明了如何使用“调用代码”“反序列化 JSON 数组”等活动来创建 JSON 数组,将其反序列化,并提供提取的令牌的列表。您可以在“UiPath.WebAPI.Activities ”包中找到这些活动。

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

  1. 打开 Studio ,创建一个新“流程”

  2. 将“序列”容器拖动至“工作流设计器”

  3. 创建以下变量:

    变量名称变量类型默认值
    jsonAsString字符串
    jsonAsArray数组
  4. Add an Invoke Code activity inside the Sequence.

    • 选择“编辑代码”按钮,并在打开的窗口中添加以下代码:

      Dim obj As ArrayList = New ArrayList()
      obj.Add("Starcraft")
      obj.Add("DOTA 2")
      obj.Add("FarCry")
      Out = JsonConvert.SerializeObject(obj)
      Dim obj As ArrayList = New ArrayList()
      obj.Add("Starcraft")
      obj.Add("DOTA 2")
      obj.Add("FarCry")
      Out = JsonConvert.SerializeObject(obj)
      
    • 添加代码后,选择“确定”按钮。

    • Select the Edit Arguments button and add the following argument:

      参数方向类型
      out输出字符串jsonAsString
    • 完成后,选择“确定”按钮,如以下动图所示:

      文档图像

  5. “日志消息”活动拖动到“调用代码”活动之后。

    • 在“行”字段中添加表达式“"JSON As String: "+jsonAsString”。
  6. “日志消息”活动之后添加“反序列化 JSON 数组”活动。

    • Add the variable jsonAsString in the Json String field.
    • In the Properties panel, add the variable jsonAsArray in the JsonArray field.
  7. “遍历循环”活动添加到“反序列化 JSON 数组”活动之后。

    • Add the value token in the ForEach field.
    • 在“VB 表达式”字段中添加 jsonAsArray 变量。
    • In the Properties panel, in the TypeArgument field, make sure you chose JValue.
  8. Add a Log Message activity inside the Body of the For Each activity.

    • 在“行”字段中添加表达式“token.ToString”。

    您的工作流应如下所示:

    文档图像

  9. 运行流程。 系统将创建一个 JSON 数组,将其反序列化为字符串,并作为提取的令牌列表提供。

您可在此处下载示例。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新