简体   繁体   English

使用“Key”作为变量 Azure Logic Apps 从简单的 JSON 获取“Value”

[英]Get "Value" from simple JSON using "Key" as variable Azure Logic Apps

I have defined a simple JSON我定义了一个简单的 JSON

{
  "12345": "Numbers",
  "AAAAA": "AllAs",
  "ABCXYZ": "AtoZ"
}

All I want to extract the value of "Key" when passed as a variable.当作为变量传递时,我只想提取“Key”的值。 I have tried body('Parse_JSON')['name'] but its failing.我试过body('Parse_JSON')['name']但它失败了。

I just want to get the value of what ever Key I am looking for as variable.我只想获得我正在寻找的任何 Key 的值作为变量。 在此处输入图像描述

As per your comment as you are initializing ABCXYZ value and that you have already declared in inputs you can just type ABCXYZ in value rather than calling Name variable根据您在初始化ABCXYZ值并且您已经在输入中声明的评论,您可以只输入ABCXYZ值而不是调用Name变量

在此处输入图像描述

Figured it !想通了!

body('parse_JSON')?[variables('name')]

The above does the following:以上执行以下操作:

1- body('parse_JSON') gets the body of Parsed JSON 1- body('parse_JSON')获取解析后 JSON 的正文

2- ?[variables('name')] gets the value of name which is equal to ABCXYZ 2- ?[variables('name')]获取name的值等于ABCXYZ

3- Returns AtoZ 3- 返回AtoZ

For those also just starting with logic apps - if its not immediately apparent;对于那些刚开始使用逻辑应用程序的人来说——如果不是很明显的话;

At "Initialize Variable 2" you need to use the "Expression" tab to input the line在“初始化变量 2”中,您需要使用“表达式”选项卡输入行

body('parse_JSON')?[variables('name')]

I just want to add something here as I was looking for a way to use a dynamics value passed in to then use that to look up in a json body to translate that value to a different.我只是想在这里添加一些东西,因为我正在寻找一种方法来使用传入的动态值,然后使用它在 json 主体中查找以将该值转换为不同的值。

Mapping value eg.映射值例如。 {"male":"M", "female":"F", "Non-Specific":"O"} {“男”:“M”,“女”:“F”,“非特定”:“O”}

So I receive the value "Male" but I need that to return as M所以我收到值“男性”,但我需要它作为 M 返回

to achieve this in a logic app the above partially gets you there.要在逻辑应用程序中实现这一点,上面的部分内容可以帮助您实现目标。

body('Parse_JSON_gender_mapping')?[string(variables('received_gender'))]

I had to wrap my use of the variable for the value we received in string() function, even though the value was a string.我不得不将我对变量的使用包装为我们在 string() function 中收到的值,即使该值是一个字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM