繁体   English   中英

如何使用 Json Extractor 从 Jmeter 中嵌套的 Json 中提取数据

[英]How to extract data from nested Json in Jmeter using Json Extractor

{"data": {"callOrders": [{ "promotionId": null, "Promotion": null, "Lines": [ { "id": 5105808, "quantity": 10, "skuId": 769, "callId" ": 494285, "skuBatchId": 733, "amountDetails": { "rate": 197.53, "grossAmount": 2232.089, "netAmount": 2232.089, "taxAmount": 256.789, "taxable":191957Total" , "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 197.53 , "rlpWithVat": 223.2089, "netPrice": 197.53, "netPriceWithVat": 223.2089, "__typename": "RateDetail" }, "SKU": { "id": 769, "title": "H&S 2in1 ml Active Protect 18 x 24 [82302894]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 197.53, "dlp": 186.35, "vatPercentage": 0.13, "mrpSrp": 250, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00 -00", "expiry": "0000-00-00", "__typename": "SKUUsag e" }, "updatedAt": "2019-11-05", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type ": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": " INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105809, "quantity": 50, "skuId": 95, "callId": 494285, "skuBatchId": 111, "amountDetails" : { "rate": 56.89, "grossAmount": 3214.2852, "netAmount": 3214.285, "taxAmount": 369.785, "taxableAmount": 2844.5, "subTotal": 2844.5, "bill, Discount:0" "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 56.89, "rlpWithVat": 64.2857, "netPrice": 56.89, "netPriceWithVat": 64.2857, "__typename": "RateDetail" }, "SKU": { "id": 95, "title": "Whisper Choice 6s x 96 [82252488]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 56.89, "dlp": 53.67, "vatPercentage": 0.13, "mr pSrp": 72, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture" : "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2016-08-15", "active": true, "__typename ": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" } , "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105810, "数量”:10,“skuId”:82,“callId”:494285,“skuBatchId”:551,“amountDetails”:{“rate”:281.88,“grossAmount”:3185.244,“netAmount”:3185.244,“taxAmount”: 366.444, "taxableAmount": 2818.8, "subTotal": 2818.8, "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail " }, "rateDetails": { "rlp": 281.88, "rlpWithVat": 318.5244, "netPrice": 281.88, "ne tPriceWithVat": 318.5244, "__typename": "RateDetail" }, "SKU": { "id": 82, "title": "Ariel Oxyblu 1 kg x 24 [82250306]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 281.88, "dlp": 268.45, "vatPercentage": 0.13, "mrpSrp": 344, "mrpStatus": true, "__typename": "SKUPrice" }, " batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2018-01-31", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title" : null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false } ], "__typename": "PromotionOrder" }]}}

使用 $..Lines..id 我得到这个 [ 5105808, 769, null, 5105809, 95, null, 5105810, 82, null ]

但我只想获得价值 [ 5105808, 5105809, 5105810] 。 实现它的方法应该是什么?

这是一个可能的解决方案:

$..[?(@.skuId)].id

这将获取具有 skuId 属性的元素并提取 id 属性。

您正在使用..这是一个深度扫描运算符,这意味着您正在查找所有id属性值,无论它们位于 JSON 中的哪个位置。

如果您只想获取作为Lines对象的直接子级的属性的id - 您需要将查询修改为: $..Lines[*].id

演示:

在此处输入图片说明

更多信息: JMeter 的 JSON 路径提取器插件 - 高级使用场景

暂无
暂无

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

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