从多个数组中提取值



我当前正在使用Adobe Echosign API将表格格式化一些数据。输出看起来像这样:

{
  "agreementId": "",
  "events": [
    {
      "actingUserEmail": "",
      "actingUserIpAddress": "",
      "date": "date",
      "description": "",
      "participantEmail": "",
      "type": "",
      "versionId": ""
    }
  ],
  "locale": "",
  "modifiable": false,
  "name": "",
  "nextParticipantSetInfos": [
    {
      "nextParticipantSetMemberInfos": [
        {
          "email": "",
          "waitingSince": "date"
        }
      ]
    }
  ],
  "participantSetInfos": [
    {
      "participantSetId": "",
      "participantSetMemberInfos": [
        {
          "email": "",
          "participantId": ""
        }
      ],
      "roles": [
        ""
      ],
      "status": ""
    }
  ],
  "status": "",
  "vaultingEnabled": false
}

我正在通过多个协议进行循环,这将它们作为一个单独的数组输出。

这可能是一个真正的基本问题,但是我如何浏览每个数组并提取说"参与者邮件","名称"one_answers"状态"值?

谢谢!

取决于您使用的编程语言,有很多方法可以处理。在JS中,您可以将此JSON数组转换为JS对象阵列,然后您可以使用JS处理访问它们。

JS的示例是:

var input = 'yourJSONstring';
var jsObject = JSON.parse(input);
for(var foo in jsObject){
	var name = foo.name;
    var participantEmail=  foo.events[0].participantEmail;
    var status = foo.participantEmail[0].status;
}

假设您与所提供的格式有一系列协议,可以做这样的事情:

<?php
$json = '[{
  "agreementId": "",
  "events": [
    {
      "actingUserEmail": "",
      "actingUserIpAddress": "",
      "date": "date",
      "description": "",
      "participantEmail": "an email",
      "type": "",
      "versionId": ""
    }
  ],
  "locale": "",
  "modifiable": false,
  "name": "a name",
  "nextParticipantSetInfos": [
    {
      "nextParticipantSetMemberInfos": [
        {
          "email": "",
          "waitingSince": "date"
        }
      ]
    }
  ],
  "participantSetInfos": [
    {
      "participantSetId": "",
      "participantSetMemberInfos": [
        {
          "email": "",
          "participantId": ""
        }
      ],
      "roles": [
        ""
      ],
      "status": "a status"
    }
  ],
  "status": "",
  "vaultingEnabled": false
}]';
$parsed = json_decode($json, true);
$names = [];
foreach($parsed as $agreement) {
    $names[] = $agreement['name'];
    $emails = []; 
    foreach($agreement['events'] as $event) {
        $emails[] = $event['participantEmail'];
    }
    $status = []; 
    foreach($agreement['participantSetInfos'] as $participant) {
        $status[] = $participant['status'];
    }
}
var_dump($names);
var_dump($emails);
var_dump($status);

当然,您应该对空值进行一些检查,但只是为了给您一个想法。由于您没有澄清名称,状态和电子邮件之间的关系,因此我只是将它们带到了单独的数组中,但这是无法通过某些数组处理而无法修复的。

希望这会有所帮助!

相关内容

  • 没有找到相关文章

最新更新