今天,我需要為公共 API 使用者創(chuàng)建一個(gè)集成測(cè)試,并檢查我找到的記錄是否與查詢(xún)參數(shù)匹配。例如,我發(fā)送一個(gè) GET 請(qǐng)求,例如localhost:8080/nutritionix/productDetails?query=grilled 我想找出包含“grilled”或“Grilled”或其他形式的相同短語(yǔ)的每個(gè)產(chǎn)品,例如:food_name 字段中的“GRillEd”短語(yǔ)。來(lái)自公共 API 的示例響應(yīng):[ { "food_name": "chicken grilled", "serving_qty": 1, "serving_unit": "piece", "photo": { "thumb": "https://d2xdmhkmkbyw75.cloudfront.net/1714_thumb.jpg" } }, { "food_name": "grilled chicken thigh", "serving_qty": 1, "serving_unit": "thigh with skin", "photo": { "thumb": "https://d2xdmhkmkbyw75.cloudfront.net/8724_thumb.jpg" } }, { "food_name": "grilled chicken wrap", "serving_qty": 1, "serving_unit": "wrap", "photo": { "thumb": "https://d2xdmhkmkbyw75.cloudfront.net/2562_thumb.jpg" } }, { "food_name": "grilled cheese", "serving_qty": 1, "serving_unit": "sandwich", "photo": { "thumb": "https://d2xdmhkmkbyw75.cloudfront.net/1763_thumb.jpg" } }, { "food_name": "Grilled Tilapia, Signature Grilled", "serving_qty": 1, "serving_unit": "fillet", "brand_name": "Gorton's", "nix_brand_id": "51db37b2176fe9790a8985bc", "photo": { "thumb": "https://d1r9wva3zcpswd.cloudfront.net/55178d395108f25f51667c2d.jpeg" } }, { "food_name": "Grilled Gourmet Soft Taco, Grilled Chicken", "serving_qty": 189, "serving_unit": "g", "brand_name": "Amigos Kings Classic", "nix_brand_id": "521b95434a56d006cae297dc", "photo": { "thumb": "https://d2eawub7utcl6.cloudfront.net/images/nix-apple-grey.png" } }]我想要實(shí)現(xiàn)的是檢查我在 JSON 響應(yīng)中收到的所有對(duì)象是否在 food_name 字段中包含一個(gè)短語(yǔ),我們?cè)诓樵?xún)期間將其作為查詢(xún)參數(shù)傳遞,包括小寫(xiě)和大寫(xiě)字母以及有趣的文本大小寫(xiě)。我想問(wèn)題的出現(xiàn)是因?yàn)榉祷氐挠涗浤J饺狈?biāo)準(zhǔn)化,例如:有時(shí)我們得到帶有 food_name 字段的對(duì)象,它們是大寫(xiě)的,有時(shí)是小寫(xiě)的。感謝您提供有關(guān)如何改進(jìn)我的 JSONPath 語(yǔ)法的任何幫助。
檢查 JSON 響應(yīng)中的每個(gè)對(duì)象是否包含特定字段中的短語(yǔ)
至尊寶的傳說(shuō)
2023-06-21 13:40:25