无法将 json 响应提取到 Jmeter Beanshell Post 处理器 \JSR223 Post 处理器中的 json 数组

Unable to fetch json response into a json array in Jmeter Beanshell Post processor \JSR223 Post processor

  1. 我有下面的 json 响应数组,我正在进入 Jmeter 正则表达式提取器变量 C_Totalresponse.

  2. 在此我有 cartItems JSON 个对象。

  3. cartItemsJSON对象中,我们有不同的SKU和对应的数量

  4. 我正在使用哈希图从 CSV 文件中读取值并更新每个 SKU 的数量详细信息,但我的脚本无法将响应提取到 Jmeter 中的数组中。

  5. 我正在分享 Jmeter 代码和我在最后解析 JSON 数组时遇到的错误

我看到很多 post 建议 groovy 我不确定如何使用它来获得像这样的巨大响应

[{"statusCode":200,"type":"rpc","tid":7,"ref":true,"action":"ccrz.cc_ctrl_CartRD","method":"fetchMiniCart","result":{"data":{"s":1,"v":{"sfid":"a5x8E000000ICRBQA4","ownerId":"0058E000005wuxmQAA","sfdcName":"00000563","encryptedId":"b86853d1-2929-44bb-84de-826bb350ff59","activeCart":true,"cartStatus":"Open","cartType":"Cart","lastModifiedDate":1615952024000,"name":"New Cart","effectiveAccountID":"0010Y00001cdP0yQAE","b2BCCTMCCount":1,"b2BCCRYOCount":0,"b2BCCCIGARCount":0,"b2BCCOTHERCount":0,"b2BCCIsEmergency":false,"b2BCCIsOffSchedule":false,"b2BCCIsFlagged":false,"b2BCCProductCount":1,"b2BCCTotalSticks":200,"b2BCCTotalGrams":0,"b2BCCExciseRemainingGrams":199670,"b2BCCExciseRemainingSticks":97800,"b2BCCNumberOfOrdersToday":0,"b2BCCOrderingDate":1615939200000,"b2},"cartItems":{"s":55,"v":[{"s":56,"v":{"sfid":"a5w8E000000LFa5QAG","sfdcName":"00068652","cart":"a5x8E000000ICRBQA4","quantity":0,"price":330.53,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":266,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.30,"b2BCCAvgSales13Weeks":0.50,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFa5QAG","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,},{"s":60,"v":{"sfid":"a5w8E000000LFa3QAG","sfdcName":"00068650","cart":"a5x8E000000ICRBQA4","quantity":0,"price":13.00,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":264,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFa3QAG","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":61,"v":{"sfid":"a6w8E00000096F3QAI","sfdcName":"WINNIES ROLLING PAPERS 50","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797287227","b2BCCProductCategory":"Other","b2BCCSTMCode":"000000000050055946","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":50},"shortDesc":"WINNIES ROLLING PAPERS 50","id":"a6w8E00000096F3QAI","sku":"50055946","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":1.000000,"UnitOfMeasure":"BX","showSubscriptionSelection":false,"name":"WINNIES ROLLING PAPERS 50","price":13.00}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096F3QAI","ccrz__SKU__c":"50055946"}}},{"s":62,"v":{"sfid":"a5w8E000000LFa2QAG","sfdcName":"00068649","cart":"a5x8E000000ICRBQA4","quantity":0,"price":35.73,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":262,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFa2QAG","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":63,"v":{"sfid":"a6w8E00000096EtQAI","sfdcName":"CAPTAIN BLACK DARK CREMA (20) ","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"71737493045","b2BCCProductCategory":"CIGAR","b2BCCSTMCode":"000000000075002330","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":44},"shortDesc":"CAPTAIN BLACK DARK CREMA (20) ","id":"a6w8E00000096EtQAI","sku":"50050031","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":20.000000,"UnitOfMeasure":"PK","showSubscriptionSelection":false,"name":"CAPTAIN BLACK DARK CREMA (20) ","price":35.73}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096EtQAI","ccrz__SKU__c":"50050031"}}},{"s":64,"v":{"sfid":"a5w8E000000LFa1QAG","sfdcName":"00068648","cart":"a5x8E000000ICRBQA4","quantity":0,"price":35.73,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":261,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFa1QAG","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":65,"v":{"sfid":"a6w8E00000096EyQAI","sfdcName":"CAPTAIN BLACK CHERISE (20)","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"71737493076","b2BCCProductCategory":"CIGAR","b2BCCSTMCode":"000000000075002330","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":47},"shortDesc":"CAPTAIN BLACK CHERISE (20)","id":"a6w8E00000096EyQAI","sku":"50050070","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":20.000000,"UnitOfMeasure":"PK","showSubscriptionSelection":false,"name":"CAPTAIN BLACK CHERISE (20)","price":35.73}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096EyQAI","ccrz__SKU__c":"50050070"}}},{"s":66,"v":{"sfid":"a5w8E000000LFa0QAG","sfdcName":"00068647","cart":"a5x8E000000ICRBQA4","quantity":0,"price":35.73,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":260,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFa0QAG","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":67,"v":{"sfid":"a6w8E00000096ACQAY","sfdcName":"CAPTAIN BLACK CLASSIC (20)","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"71737493014","b2BCCProductCategory":"CIGAR","b2BCCSTMCode":"000000000075002330","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":32},"shortDesc":"CAPTAIN BLACK CLASSIC (20)","id":"a6w8E00000096ACQAY","sku":"50050062","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":20.000000,"UnitOfMeasure":"PK","showSubscriptionSelection":false,"name":"CAPTAIN BLACK CLASSIC (20)","price":35.73}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096ACQAY","ccrz__SKU__c":"50050062"}}},{"s":68,"v":{"sfid":"a5w8E000000LFZpQAO","sfdcName":"00068636","cart":"a5x8E000000ICRBQA4","quantity":0,"price":48.49,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":208,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":8.80,"b2BCCAvgSales8Weeks":11.90,"b2BCCAvgSales13Weeks":12.70,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZpQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":69,"v":{"sfid":"a6w8E000000969ZQAQ","sfdcName":"PORT ROYAL 25G RUM & WINE RYO","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797281683","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075025978","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":29},"shortDesc":"PORT ROYAL 25G RUM & WINE RYO","id":"a6w8E000000969ZQAQ","sku":"10065793","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":25.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"PORT ROYAL 25G RUM & WINE RYO","price":48.49}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000969ZQAQ","ccrz__SKU__c":"10065793"}}},{"s":70,"v":{"sfid":"a5w8E000000LFZoQAO","sfdcName":"00068635","cart":"a5x8E000000ICRBQA4","quantity":0,"price":45.22,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":206,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.20,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZoQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":71,"v":{"sfid":"a6w8E000000963wQAA","sfdcName":"PORT ROYAL 25G RAW","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797286466","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075090737","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":17},"shortDesc":"PORT ROYAL 25G RAW","id":"a6w8E000000963wQAA","sku":"10065785","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":25.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"PORT ROYAL 25G RAW","price":45.22}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000963wQAA","ccrz__SKU__c":"10065785"}}},{"s":72,"v":{"sfid":"a5w8E000000LFZnQAO","sfdcName":"00068634","cart":"a5x8E000000ICRBQA4","quantity":0,"price":28.79,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":204,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZnQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":73,"v":{"sfid":"a6w8E000000966vQAA","sfdcName":"PORT ROYAL 15G ORIG RUM & WINE","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797283847","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075076853","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":26},"shortDesc":"PORT ROYAL 15G ORIG RUM & WINE","id":"a6w8E000000966vQAA","sku":"10065881","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":15.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"PORT ROYAL 15G ORIG RUM & WINE","price":28.79}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000966vQAA","ccrz__SKU__c":"10065881"}}},{"s":74,"v":{"sfid":"a5w8E000000LFZmQAO","sfdcName":"00068633","cart":"a5x8E000000ICRBQA4","quantity":0,"price":28.79,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":202,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZmQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":75,"v":{"sfid":"a6w8E000000966cQAA","sfdcName":"PORT ROYAL 15G HIGHLAND WHISKY","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797283861","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075079687","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":23},"shortDesc":"PORT ROYAL 15G HIGHLAND WHISKY","id":"a6w8E000000966cQAA","sku":"10041618","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":3.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"PORT ROYAL 15G HIGHLAND WHISKY","price":28.79}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000966cQAA","ccrz__SKU__c":"10041618"}}},{"s":76,"v":{"sfid":"a5w8E000000LFZlQAO","sfdcName":"00068632","cart":"a5x8E000000ICRBQA4","quantity":0,"price":41.92,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":199,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":1.30,"b2BCCAvgSales13Weeks":2.30,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZlQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":77,"v":{"sfid":"a6w8E00000096BgQAI","sfdcName":"HOLIDAY 25G BRIGHT BLUE","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797281669","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075025968","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":38},"shortDesc":"HOLIDAY 25G BRIGHT BLUE","id":"a6w8E00000096BgQAI","sku":"10088017","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":25.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"HOLIDAY 25G BRIGHT BLUE","price":41.92}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096BgQAI","ccrz__SKU__c":"10088017"}}},{"s":78,"v":{"sfid":"a5w8E000000LFZkQAO","sfdcName":"00068631","cart":"a5x8E000000ICRBQA4","quantity":0,"price":26.51,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":195,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.00,"b2BCCAvgSales13Weeks":0.00,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZkQAO","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":79,"v":{"sfid":"a6w8E00000096BhQAI","sfdcName":"CAPSTAN 15G MAKERS BLEND","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797285476","b2BCCProductCategory":"RYO","b2BCCSTMCode":"000000000075087239","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":41},"shortDesc":"CAPSTAN 15G MAKERS BLEND","id":"a6w8E00000096BhQAI","sku":"10088018","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":15.000000,"UnitOfMeasure":"PA","showSubscriptionSelection":false,"name":"CAPSTAN 15G MAKERS BLEND","price":26.51}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096BhQAI","ccrz__SKU__c":"10088018"}}},{"s":80,"v":{"sfid":"a5w8E000000LFZFQA4","sfdcName":"00068600","cart":"a5x8E000000ICRBQA4","quantity":0,"price":188.56,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":12,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":2.50,"b2BCCAvgSales8Weeks":4.10,"b2BCCAvgSales13Weeks":4.20,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZFQA4","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":81,"v":{"sfid":"a6w8E000000965pQAA","sfdcName":"B&H 30/120 SMOOTH BLUE","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797285537","b2BCCProductCategory":"TMC","b2BCCSTMCode":"000000000075089380","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":20},"shortDesc":"B&H 30/120 SMOOTH BLUE","id":"a6w8E000000965pQAA","sku":"10086360","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":120.000000,"UnitOfMeasure":"CT","showSubscriptionSelection":false,"name":"B&H 30/120 SMOOTH BLUE","price":188.56}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000965pQAA","ccrz__SKU__c":"10086360"}}},{"s":82,"v":{"sfid":"a5w8E000000LFZEQA4","sfdcName":"00068599","cart":"a5x8E000000ICRBQA4","quantity":0,"price":188.56,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":11,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":3.00,"b2BCCAvgSales8Weeks":4.00,"b2BCCAvgSales13Weeks":4.60,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZEQA4","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":83,"v":{"sfid":"a6w8E00000096BVQAY","sfdcName":"B&H 30/120 CLASSIC RED","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797285520","b2BCCProductCategory":"TMC","b2BCCSTMCode":"000000000075089380","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":35},"shortDesc":"B&H 30/120 CLASSIC RED","id":"a6w8E00000096BVQAY","sku":"10086472","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":120.000000,"UnitOfMeasure":"CT","showSubscriptionSelection":false,"name":"B&H 30/120 CLASSIC RED","price":188.56}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E00000096BVQAY","ccrz__SKU__c":"10086472"}}},{"s":84,"v":{"sfid":"a5w8E000000LFZDQA4","sfdcName":"00068598","cart":"a5x8E000000ICRBQA4","quantity":0,"price":330.53,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":9,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.50,"b2BCCAvgSales8Weeks":0.90,"b2BCCAvgSales13Weeks":0.90,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZDQA4","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":85,"v":{"sfid":"a6w8E0000009632QAA","sfdcName":"B&H 25/200 FINE GREY FF","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797002615","b2BCCProductCategory":"TMC","b2BCCSTMCode":"000000000075001150","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":14},"shortDesc":"B&H 25/200 FINE GREY FF","id":"a6w8E0000009632QAA","sku":"10014887","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":200.000000,"UnitOfMeasure":"CT","showSubscriptionSelection":false,"name":"B&H 25/200 FINE GREY FF","price":330.53}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E0000009632QAA","ccrz__SKU__c":"10014887"}}},{"s":86,"v":{"sfid":"a5w8E000000LFZBQA4","sfdcName":"00068596","cart":"a5x8E000000ICRBQA4","quantity":1,"price":330.53,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":330.53,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":6,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":0.00,"b2BCCAvgSales8Weeks":0.30,"b2BCCAvgSales13Weeks":0.50,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZBQA4","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":87,"v":{"sfid":"a6w8E000000962OQAQ","sfdcName":"B&H 25/200 SMOOTH DRK BLUE FF","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797002516","b2BCCProductCategory":"TMC","b2BCCSTMCode":"000000000075001150","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":5},"shortDesc":"B&H 25/200 SMOOTH DRK BLUE FF","id":"a6w8E000000962OQAQ","sku":"10014748","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":200.000000,"UnitOfMeasure":"CT","showSubscriptionSelection":false,"name":"B&H 25/200 SMOOTH DRK BLUE FF","price":330.53}},"qtyIncrement":1,"SubAmount":330.53,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000962OQAQ","ccrz__SKU__c":"10014748"}}},{"s":88,"v":{"sfid":"a5w8E000000LFZAQA4","sfdcName":"00068595","cart":"a5x8E000000ICRBQA4","quantity":0,"price":330.53,"productType":"Product","storeID":"B2BAUSECOMMERCE","pricingType":"auto","itemTotal":0.00,"cartItemType":"Major","itemStatus":"Available","b2BCCSubAmountDiscount":0.00,"b2BCCIsFeatured":false,"b2BCCIsStrategic":false,"b2BCCSequence":5,"b2BCCPromotionTotal":0.00,"b2BCCPromotionZSC1":0.00,"b2BCCPromotionZSM1":0.00,"b2BCCPromotionZSP1":0.00,"b2BCCPromoCappingOverflowPrice":0.00,"b2BCCPromoCappingOverflowQty":0,"b2BCCAvgSales4Weeks":1.00,"b2BCCAvgSales8Weeks":1.60,"b2BCCAvgSales13Weeks":2.10,"sfdcCurrencyISOCode":"AUD","itemID":"a5w8E000000LFZAQA4","cartId":"a5x8E000000ICRBQA4","showSubProdTerm":false,"mockProduct":{"s":89,"v":{"sfid":"a6w8E000000962YQAQ","sfdcName":"B&H 25/200 CLASSIC RED FF","ownerId":"0058E000007MQgfQAG","storefront":"B2BAUSECOMMERCE","startDate":1577836800000,"endDate":7258032000000,"averageRating":0.00,"taxable":false,"inventoryType":"STANDARD","b2BCCBarcode":"9310797002011","b2BCCProductCategory":"TMC","b2BCCSTMCode":"000000000075001150","sfdcCurrencyISOCode":"GBP","EProductMediasS":{"r":8},"shortDesc":"B&H 25/200 CLASSIC RED FF","id":"a6w8E000000962YQAQ","sku":"10014816","ProductType":"Product","ProductStatus":"Released","qtyPerUnit":200.000000,"UnitOfMeasure":"CT","showSubscriptionSelection":false,"name":"B&H 25/200 CLASSIC RED FF","price":330.53}},"qtyIncrement":1,"SubAmount":0.00,"adjustment":0,"baseDiscount":0,"absoluteDiscount":0,"product":{"Id":"a6w8E000000962YQAQ","ccrz__SKU__c":"10014816"}}}]},"cartItemCount":1}},"inputContext":{"currentCartId":"b86853d1-2929-44bb-84de-826bb350ff59","currentPageName":"ccrz__ProductList","currentPageURL":"https://batuat-batglobalb2b.cs87.force.com/B2BAUSECOMMERCE/ccrz__ProductList?effectiveAccount=0010Y00001cdP0yQAE&refURL=https%3A%2F%2Fbatuat-batglobalb2b.cs87.force.com%2FB2BAustraliaCommunity%2Fs%2F","effAccountId":"0010Y00001cdP0yQAE","portalUserId":"","priceGroupId":"","queryParams":{"s":90,"v":{}},"storefront":"B2BAUSECOMMERCE","userIsoCode":"AUD","userLocale":"en_US"},"messages":{"s":91,"v":[]},"success":true}}]

下面是我上面提到的步骤在 Jmeter 中的代码

import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import groovy.json.JsonSlurper;
import org.json.JSONArray;
import org.json.JSONObject;
import com.eclipsesource.json.*;

String Path = "\\fjsvdishares\85039042\Documents\2021\J-Meter\data.csv";


try 
    {
                      
           
         String test = org.apache.commons.io.FileUtils.readFileToString(new File(Path));
           
                Map map = new HashMap();

        map.put(vars.get("SKU"),vars.get("quantity"));
             
    
            JSONParser jsonParser = new JSONParser();                 
            JSONArray cartItemsList = null;
            JSONObject cartItemsObj = null;

                    

             String jsonString = vars.get("C_Totalresponse");

         
         JSONObject cartItemsObj = (JSONObject) jsonParser.parse(jsonString);
         SONArray cartItemsList = (JSONArray) cartItemsObj.get("cartItems");
          
          
            Iterator it = map.entrySet().iterator();
            while (it.hasNext() ) {

                Map.Entry pair = (Map.Entry)it.next();
                
                if(cartItemsList.size() > 0 ) {  

                    for(int i = 0; i < cartItemsList.size(); i++){

                        JSONObject object = (JSONObject) cartItemsList.get(i);

                        JSONObject productJsonObj = (JSONObject)object.get("product") ; 
                        
                        

                        if( productJsonObj.get("ccrz__SKU__c").toString() .equals(pair.getKey().toString()) ) {   

                            object.put("quantity" , pair.getValue()); 
                        }

                        
                          
                    }
                }
                    
            }
           
                   
       }

        catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
           e.printStackTrace();
        } catch (ParseException e) {
           e.printStackTrace();
        }

错误详情如下:

2021-03-17 07:42:03,146 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor javax.script.ScriptException: Sourced file: inline evaluation of: import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . '' : Typed variable declaration : at Line: 48 : in file: inline evaluation of: import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . '' : ( JSONObject ) jsonParser .parse ( jsonString )

Target exception: java.lang.ClassCastException: Cannot cast org.json.simple.JSONArray to org.json.JSONObject in inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . '' at line number 48

我认为这条线有问题(至少)

JSONObject cartItemsObj = (JSONObject) jsonParser.parse(jsonString)

我认为您需要将其更改为:

JSONArray cartItemsObj = (JSONArray ) jsonParser.parse(jsonString)

我无法对您的代码作进一步评论,因为您的 JSON 无效,而且您想要实现的目标也不是很清楚。

关于使用 Groovy - 这是您真正应该考虑的事情,因为:

  1. Groovy has much better performance comparing to Beanshell
  2. Groovy has built-in JSON support
  3. Groovy is more compatible with Java and supports all modern Java runtime features

我尝试了很多关于 Beanshell 处理器代码的帖子,以从 haspmap 读取数据并使用 hashmap 更新 json 请求数组值中的数据。许多人建议使用 groovy\JSR223 处理器。下面是 beanshell 中的代码,这将对许多 requests\questions 我们没有回答的用户有帮助。


import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;  
import java.util.Map;
import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.JSONArray;
import org.json.JSONObject;


String Path = "\\fjsvdishares\Documents\2021\J-Meter\data.csv";


try 
    {
                      
         BufferedReader br = new BufferedReader(new FileReader(Path));
               Map map = null;
               Map map = new HashMap(); //Creating hashmap
             String line =  null;
            while((line=br.readLine())!=null){  //writing data into hashmap from csv file
        
               StringTokenizer st = new StringTokenizer(line, ","); 
               
                       while ( st.hasMoreElements() ){
                        
                          String key = st.nextToken();
                            String value = st.nextToken();
                            map.put(key,value);
                       
                         }
  
                    } 
          
        
         
           String jsonString = vars.get("C_cartItems"); //reading json request into string          
         
           
               //code to fetch skus in request and update the quanity for the select sku 
          
        JSONArray jsonArray=new JSONArray(jsonString); 
        
            Iterator it = map.entrySet().iterator();
            int count =0;
            while (it.hasNext() ) {
                //Getting the first pair values from map object
                Map.Entry pair = (Map.Entry)it.next();

                if(jsonArray.length() > 0 ) {
                    //Iterating through the cartitem list
                    for(int i = 0; i < jsonArray.length(); i++){
                        //Getting the first cartlist item
                        JSONObject object = (JSONObject) jsonArray.getJSONObject(i);
                    JSONObject insideVObject = (JSONObject)object.getJSONObject("v") ;
                        JSONObject productJsonObj = (JSONObject)insideVObject.getJSONObject("product") ;

                                                    
                        
                       //Checking the Sku value from cartitem and map
                        if( productJsonObj.get("ccrz__SKU__c").equals(pair.getKey()) ) {      
                            //updating the quantity value with new value
                            object.put("quantity" , pair.getValue()); 
                            count++;
                        }
                          
                    }
                }
                    
                
            }   

           // log.info(count + " ...items updated");
           // log.info(" resultJson   ...." +jsonArray);
          
                   
       }

        catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
           e.printStackTrace();
        } catch (ParseException e) {
           e.printStackTrace();
        }