Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mulesoft 需要澄清以下键值对_Mulesoft - Fatal编程技术网

Mulesoft 需要澄清以下键值对

Mulesoft 需要澄清以下键值对,mulesoft,Mulesoft,说明: 输入应该是json对象 根据键按字母顺序对键、值对进行排序 生成下面示例中提到的输出 示例: 输入: { "name":"<<your_name>>", "age":"<<your_age>>", "city":"<<your_city>>", "role":"<<your_role>>" } { “名称”:“, “年龄”:“, “城市”:“, “角色”:” } 输出: age=

说明:

  • 输入应该是json对象

  • 根据键按字母顺序对键、值对进行排序

  • 生成下面示例中提到的输出

  • 示例:

    输入:

    {
    
    "name":"<<your_name>>",
    
    "age":"<<your_age>>",
    
    "city":"<<your_city>>",
    
    "role":"<<your_role>>"
    
    }
    
    {
    “名称”:“,
    “年龄”:“,
    “城市”:“,
    “角色”:”
    }
    
    输出:

    age=<<your_age>>&city=<<your_city>>&name=<<your_name>>&<<your_role>>
    
    age=&city=&name=&
    

    注意:请使用邮递员发送输入,您的代码应适用于任意数量的键、值对。

    首先让我说,如果您打算使用作为HTTP请求的查询参数字符串,这不是一个好主意。使用HTTP请求程序将每个属性作为查询参数发送给请求程序会更有意义。它将自动应用URL编码并处理参数

    例如:

    <set-variable value='#[{
      name:"&lt;&lt;your_name&gt;&gt;",
      age:"&lt;&lt;your_age&gt;&gt;",
      city:"&lt;&lt;your_city&gt;&gt;",
      role:"&lt;&lt;your_role&gt;&gt;"
    }]' doc:name="Set Variable" variableName="person"/>
    
    <http:request method="GET"  config-ref="HTTP_Request_configuration" path="/backend" >
        <http:query-params><![CDATA[#[vars.person]]]></http:query-params>
    </http:request>
    
    %dw 2.0
    output application/json
    import * from dw::core::URL
    ---
    // it is not recommended to use this, use the HTTP Requester <http:query-params> instead
    encodeURI(
        payload pluck ((value, key, index) -> 
            { key: key, value: value}
        )  
        orderBy( $.key )
        reduce ((val, acc = "") -> 
            acc ++ (if(sizeOf(acc) !=0) "&" else "") ++ val.key ++ "=" ++ val.value)
    )
    
    如果您确实觉得必须手动构建查询参数字符串,请参见下文

    例如:

    <set-variable value='#[{
      name:"&lt;&lt;your_name&gt;&gt;",
      age:"&lt;&lt;your_age&gt;&gt;",
      city:"&lt;&lt;your_city&gt;&gt;",
      role:"&lt;&lt;your_role&gt;&gt;"
    }]' doc:name="Set Variable" variableName="person"/>
    
    <http:request method="GET"  config-ref="HTTP_Request_configuration" path="/backend" >
        <http:query-params><![CDATA[#[vars.person]]]></http:query-params>
    </http:request>
    
    %dw 2.0
    output application/json
    import * from dw::core::URL
    ---
    // it is not recommended to use this, use the HTTP Requester <http:query-params> instead
    encodeURI(
        payload pluck ((value, key, index) -> 
            { key: key, value: value}
        )  
        orderBy( $.key )
        reduce ((val, acc = "") -> 
            acc ++ (if(sizeOf(acc) !=0) "&" else "") ++ val.key ++ "=" ++ val.value)
    )
    
    %dw 2.0
    输出应用程序/json
    从dw::core::URL导入*
    ---
    //不建议使用此选项,请改用HTTP请求程序
    编码URI(
    有效负载清除((值、键、索引)->
    {key:key,value:value}
    )  
    orderBy($.key)
    减少((val,acc=”“)->
    acc++(如果(sizeOf(acc)!=0)&“else”++val.key++“=”++val.value)
    )