【问题标题】:Get avalue from json list from API response in postman从邮递员的 API 响应中获取 json 列表中的值
【发布时间】:2019-06-11 14:17:37
【问题描述】:

需要获取 DisplayName 的 Id 值”:“来自 API 响应的三星 XCover 4 我试过了,但没有用。

    var response = JSON.parse(responseBody);
    {
    var count = Object.keys(response.Offerings[0]);
    console.log(count);
    for(var x =0; x <=count.length ; x++)
    { 
    if(count[x] == 'Id')
    {
    var val =   
    console.log(response.Offerings[0].count[x]);
    // console.log(pm.environment.get(count['Id']));
    }
    }
    }

来自 API 的响应:

   {
   "Offerings": [
    {
            "Amount": 292,
            "CurrencyCode": "CAD",
            "DisplayName": "Samsung XCover 4",
            "Id": 1910256761716000500,
            "Language": "en-CA",
            "LineOfBusinesses": [
                10048
            ],
            "MarketingViews": [],
            "Name": "Samsung XCover 4",
            "OfferType": 1,
            "ShortDescription": "Offering bundle includes:\n- Airtime Product\n- Samsung XCover 4 device\n- SIM Card\n- & optional device protection",

我有一个 DisplayName 和 Id 的日志列表,但我需要在其他 API 的正文中使用“DisplayName”的 ID:“Samsung XCover 4”。

【问题讨论】:

标签: json postman


【解决方案1】:

var response = JSON.parse(responseBody); for(var i=0; i

有没有办法停止四舍五入并从响应中获取确切的 ID?

【讨论】:

    【解决方案2】:

    我用过 eval(globals.bigint_fix);在测试中并将全局变量 bigint_fix 值设置为 bigint.js 脚本。

    【讨论】:

    • 也为我工作。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2021-07-22
    • 1970-01-01
    • 2018-11-23
    • 2020-07-09
    • 1970-01-01
    • 2018-03-26
    相关资源
    最近更新 更多