【发布时间】:2018-07-30 13:20:07
【问题描述】:
我正在尝试验证以下响应,它是一个没有数组名称的数组。
[
{
"soldTo": "0000100139",
"productId": "88175838",
"catalogNumber": "130C-3/4X30FT",
"manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
"quantity": "000001",
"lastPurchaseDate": "Jun 13, 2018 12:00:00 AM",
"description": "30-feet x 3/4-inch black Scotch® linerless rubber splicing tape.",
"imageUrl": "https://static.graybar.com/supplierimages/3m_new/130C-1-12X30FT-th.png"
},
{
"soldTo": "0000100139",
"productId": "25438652",
"catalogNumber": "312-POUCH",
"manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
"quantity": "000011",
"lastPurchaseDate": "Jul 27, 2018 12:00:00 AM",
"description": "Yellow Scotchlok™ electrical spring connector in a pouch for 22 to 8 AWG wire.",
"imageUrl": "https://static.graybar.com/supplierimages/3m_new/312-BAG-th.png"
},
{
"soldTo": "0000100139",
"productId": "88175944",
"catalogNumber": "33+SUPER-3/4X66FT",
"manufacturerName": "3M CO. - ELECTRICAL MARKETS DIV.",
"quantity": "000001",
"lastPurchaseDate": "Jun 13, 2018 12:00:00 AM",
"description": "66-feet x 3/4-inch black Scotch® Super 33+™ vinyl electrical tape.",
"imageUrl": "https://static.graybar.com/supplierimages/3M_New/MMM_33Super34x66FT-th.png"
}
]
当我尝试使用以下匹配每个脚本时出现错误。
And match each response.soldTo == '#string'
And match each response.productId == '#string'
And match each response.catalogNumber == '#string'
And match each response.manufacturerName == '#string'
And match each response.quantity == '#string'
And match each response.lastPurchaseDate == '#string'
And match each response.description == '#string'
And match each response.imageUrl == '#string
'
错误: com.intuit.karate.exception.KarateException:应在路径 $ 中找到具有属性 ['soldTo'] 的对象,但找到了 'net.minidev.json.JSONArray'。这不是根据 JsonProvider 的 json 对象:'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'。 在 com.intuit.karate.StepDefs.matchNamed(StepDefs.java:540) 在 com.intuit.karate.StepDefs.matchEquals(StepDefs.java:526) 在✽。并匹配每个 response.soldTo == "0000100139"(previously-order-items/previously-order-items.feature:24)
【问题讨论】:
-
使用下面的脚本得到另一个错误:并匹配每个响应 == ' """ { soldTo: '#notnull', productId: '#string', catalogNumber: '#string', manufacturerName: ' #string', 数量: '#string', lastPurchaseDate: '#string' 描述: '#string' imageUrl: '#string' } """ ' Error: com.intuit.karate.exception .KarateException: net.minidev.json.parser.ParseException: 位置 166 处的意外标记 d。
-
您能否将此答案标记为已接受:stackoverflow.com/a/51596405/143475
标签: karate