<tfoot id='B6ckt'></tfoot>

    • <bdo id='B6ckt'></bdo><ul id='B6ckt'></ul>
    <legend id='B6ckt'><style id='B6ckt'><dir id='B6ckt'><q id='B6ckt'></q></dir></style></legend>
  • <i id='B6ckt'><tr id='B6ckt'><dt id='B6ckt'><q id='B6ckt'><span id='B6ckt'><b id='B6ckt'><form id='B6ckt'><ins id='B6ckt'></ins><ul id='B6ckt'></ul><sub id='B6ckt'></sub></form><legend id='B6ckt'></legend><bdo id='B6ckt'><pre id='B6ckt'><center id='B6ckt'></center></pre></bdo></b><th id='B6ckt'></th></span></q></dt></tr></i><div id='B6ckt'><tfoot id='B6ckt'></tfoot><dl id='B6ckt'><fieldset id='B6ckt'></fieldset></dl></div>

    <small id='B6ckt'></small><noframes id='B6ckt'>

      1. 邮递员从 JSON 中获取值,其中等于使用 javascript 的数组中的值

        Postman get value from JSON where equals a value in array using javascript(邮递员从 JSON 中获取值,其中等于使用 javascript 的数组中的值)

        <small id='xz26N'></small><noframes id='xz26N'>

          <bdo id='xz26N'></bdo><ul id='xz26N'></ul>
            <tbody id='xz26N'></tbody>

              <i id='xz26N'><tr id='xz26N'><dt id='xz26N'><q id='xz26N'><span id='xz26N'><b id='xz26N'><form id='xz26N'><ins id='xz26N'></ins><ul id='xz26N'></ul><sub id='xz26N'></sub></form><legend id='xz26N'></legend><bdo id='xz26N'><pre id='xz26N'><center id='xz26N'></center></pre></bdo></b><th id='xz26N'></th></span></q></dt></tr></i><div id='xz26N'><tfoot id='xz26N'></tfoot><dl id='xz26N'><fieldset id='xz26N'></fieldset></dl></div>

              <legend id='xz26N'><style id='xz26N'><dir id='xz26N'><q id='xz26N'></q></dir></style></legend>
              <tfoot id='xz26N'></tfoot>
                  本文介绍了邮递员从 JSON 中获取值,其中等于使用 javascript 的数组中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目前使用的是Postman最新版本:6.7.4(Latest)

                  Currently using the latest version of Postman: 6.7.4 (Latest)

                  我正在尝试从 JSON 响应正文中获取一个值并将其存储在环境变量中,但值用户名"应该等于我的首选用户名.

                  I'm trying to get a value out of a JSON response body and store it in an environment variable BUT the value 'username' should be equal to my preferred username.

                  通常我会提取这样的值:

                  Normally I would extract a value like this:

                  var jsonData = pm.response.json();
                  pm.environment.set("useridToken", jsonData.Customers[0].userid);
                  

                  这会给我列表中的第一项,但我确实希望获得列表中的第一项或第二项.例如,我希望获得 userid where username EQUAL Billy".

                  This would give me the first item in the list but I do not wish to obtain the first nor the second item from the list. I wish to obtain the userid where username EQUAL "Billy" for example.

                  身体响应的输出:

                  {
                  "Customers": [
                      {
                          "id": 24,
                          "userid": 73063,
                          "username": "BOB",
                          "firstname": "BOB",
                          "lastname": "LASTNAME
                      },
                      {
                          "id": 25,
                          "userid": 73139,
                          "username": "Billy",
                          "firstname": "Billy",
                          "lastname": "lasty"
                      }
                     ]
                  }
                  

                  有什么建议吗?

                  我记得在 SoapUI 中是这样的:

                  I remember in SoapUI it was like this:

                  $.channels[?(@.is_archived=='false')].id[0]
                  

                  我想在 Postman 的 JS 中不可能做到这一点?

                  I guess it's not possible to do this in JS in Postman?

                  推荐答案

                  你可以使用:Array.prototype.find():

                  const data = {
                    "Customers": [{
                        "id": 24,
                        "userid": 73063,
                        "username": "BOB",
                        "firstname": "BOB",
                        "lastname": "LASTNAME"
                      },
                      {
                        "id": 25,
                        "userid": 73139,
                        "username": "Billy",
                        "firstname": "Billy",
                        "lastname": "lasty"
                      }
                    ]
                  }
                  
                  const user = data.Customers.find(u => u.username === 'Billy')
                  const userid = user ? user.userid : 'not found'
                  
                  console.log(user)
                  console.log(userid)

                  这篇关于邮递员从 JSON 中获取值,其中等于使用 javascript 的数组中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc
                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                    <tbody id='gtdu8'></tbody>
                1. <i id='gtdu8'><tr id='gtdu8'><dt id='gtdu8'><q id='gtdu8'><span id='gtdu8'><b id='gtdu8'><form id='gtdu8'><ins id='gtdu8'></ins><ul id='gtdu8'></ul><sub id='gtdu8'></sub></form><legend id='gtdu8'></legend><bdo id='gtdu8'><pre id='gtdu8'><center id='gtdu8'></center></pre></bdo></b><th id='gtdu8'></th></span></q></dt></tr></i><div id='gtdu8'><tfoot id='gtdu8'></tfoot><dl id='gtdu8'><fieldset id='gtdu8'></fieldset></dl></div>
                  <tfoot id='gtdu8'></tfoot>

                  • <bdo id='gtdu8'></bdo><ul id='gtdu8'></ul>

                      <small id='gtdu8'></small><noframes id='gtdu8'>

                        <legend id='gtdu8'><style id='gtdu8'><dir id='gtdu8'><q id='gtdu8'></q></dir></style></legend>