从数组中选择特定值

huangapple go评论64阅读模式
英文:

I need to pick a specific value from an array

问题

"body": {
"ShipmentResponse": {
"Notification": [
{
"@code": "0",
"Message": null
}
],
"PackagesResult": {
"PackageResult": [
{
"number": ,
"TrackingNumber":
},
{
"number":,
"TrackingNumber":
}
]
},
"LabelImage": [
{
"LabelImageFormat": "PDF",
"GraphicImage": "Value required"
}
]
}
}

从上面的响应中,我只需要提取GraphicImage的值。

我尝试使用一个数组变量和筛选数组,但LabelImageFormat和GraphicImage被视为一个单一的索引,因此我无法提取单个值。

请告诉我如何只提取所需的值,即GraphicImage。

"GraphicImage": "Value required"

提前感谢。

英文:

I have an output response from the HTTP request as shown below

"body": {
        "ShipmentResponse": {
            "Notification": [
                {
                    "@code": "0",
                    "Message": null
                }
            ],
            "PackagesResult": {
                "PackageResult": [
                    {
                        "number": ,
                        "TrackingNumber": 
                    },
                    {
                        "number":,
                        "TrackingNumber": 
                    }
                ]
            },
            "LabelImage": [
                {
                    "LabelImageFormat": "PDF",
                    "GraphicImage": "Value required"
                 }
            ],

From the above response I need to fetch only the GraphicImage value.

I tried by using a array variable anf Filter array but LabelImageFormat and Graphic Image is treated as one single Index, as a result of which I am unable to fetch a single value.

Please let me know how I can fetch only the value required that is Graphic Image.

"GraphicImage": "Value required"

Thanks in Advance

答案1

得分: 0

这应该很容易使用ParseJson操作。

  1. 解析JSON

    收到HTTP响应后,添加一个'Parse JSON'操作。

    对于内容,提供HTTP响应的正文(例如,outputs('HTTP_action_name').body)。

    对于模式,您可以使用您提供的示例负载来生成它。

  2. 提取GraphicImage的值

    在解析JSON后,您可以通过'Parse JSON'操作的输出直接访问GraphicImage的值。

    添加一个新的操作(如'Set variable'或'Compose'),其值使用以下表达式:

    outputs('Parse_JSON_action_name')?['body/ShipmentResponse/LabelImage'][0]?['GraphicImage']
    

    Parse_JSON_action_name替换为您的'Parse JSON'操作的名称。

  3. 使用该值

    在上述步骤之后,GraphicImage的值将存储在变量或Compose操作中。然后,您可以根据需要在您的Logic App的后续步骤中使用它。

英文:

This should be easy with ParseJson Action.

  1. Parse the JSON:

    After receiving the HTTP response, add a 'Parse JSON' action.

    For the content, provide the body of the HTTP response (e.g., outputs('HTTP_action_name').body).

    For the schema, you can use the sample payload you provided to generate it.

  2. Extract the GraphicImage Value:

    After parsing the JSON, you can access the GraphicImage value directly through the outputs of the 'Parse JSON' action.

    Add a new action (like 'Set variable' or 'Compose') and for its value, use the following expression:

    outputs('Parse_JSON_action_name')?['body/ShipmentResponse/LabelImage'][0]?['GraphicImage']
    

    Replace Parse_JSON_action_name with the name of your 'Parse JSON' action.

  3. Use the Value:

    After the above step, the GraphicImage's value will be stored in the variable or the Compose action. You can then use it in subsequent steps of your Logic App as needed.

答案2

得分: 0

个人认为这将是最简单的方法...

first(body('HTTP')['ShipmentResponse']['LabelImage'])['GraphicImage']

...注意到你的HTTP操作被命名为 HTTP

英文:

Personally I think this would be the easiest approach ...

first(body('HTTP')['ShipmentResponse']['LabelImage'])?['GraphicImage']

... noting that your HTTP operation is named HTTP.

huangapple
  • 本文由 发表于 2023年8月10日 23:04:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877018.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定