从JSON请求主体获取值并将其存储在Azure API管理中的变量中 [英] Fetch value from json request body and store in a variable in Azure API Management

查看:80
本文介绍了从JSON请求主体获取值并将其存储在Azure API管理中的变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从json中获取一个值并将其存储在Azure API Management中的变量中.请求正文中出现的JSON示例是

I want to fetch a value from json and store it in a variable in Azure API Management. JSON Example which is coming in request Body is

{
    "ItemCode": 1,
    "ItemName": "USA",
    "typeCode": "REG"
  }

我需要获取ItemCode和typeCode的值并将其存储在变量中.

I need to fetch value of ItemCode and typeCode and store it in a variable.

我已经检查了Microsoft Docs,它提供了所有使用液体模板来转换主体的功能,我认为这对我没有用.

I have check on Microsoft Docs and all it gives me to transform body by using liquid template which I suppose is of no use in my requirement.

我已经在类似

set-variable name="varItemCode" value="@(context.Request.Body.As<String>(preserveContent:true))" />

由于它存储了一个字符串,所以我无法遍历JSON对象.

Since this is stored a string I am not able to traverse the JSON Object.

推荐答案

我能够做到

<kbd>set-variable name="varTypeCode" value="@{
                    JObject json = JObject.Parse(context.Variables.GetValueOrDefault<string>("varBody"));
                    var typeCode = json.GetValue("typeCode");
                    return typeCode;
                 }" />

这篇关于从JSON请求主体获取值并将其存储在Azure API管理中的变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆