获取 ids 数组,但需要获取 String
getting array of ids , but need to get String
我正在测试 API 放心,并尝试使用以下方法从我创建的产品中获取 Id 作为字符串
String productId = response.jsonPath().getString("productPrices.productId");
String channelId = response.jsonPath().getString("productPrices.channelId");
但它返回一个数组
当我打印出这些 ID 时,得到以下输出;
System.out.println("productId is ===> " +productId);
System.out.println("channelId is ===> " +channelId);
输出为
productId is ===>[jpjeneOM]
channelId is ===>[5bpJKaVE]
我的问题是,我只需要将这些 ID 作为字符串获取!!!
请帮我解决这个问题
提前致谢
我有以下负载
{
"id": "jpjeneOM",
"name": "NewProductForTest",
"productTypeId": null,
"active": true,
"shortDescription": "API",
"fullDescription": "API Automation",
"policy": null,
"mostPopular": null,
"longitude": 34.774667,
"latitude": 32.085814,
"calendarColor": "blue",
"address": "Dizengoff Street, Tel Aviv-Yafo",
"cityId": "nlYxZ6az",
"createdAt": "2021-08-06T07:49:14.920615",
"productImages": [
],
"productDocuments": [
],
"productTypes": null,
"productWorkingDates": [
{
"id": "baQkKROA",
"productId": "jpjeneOM",
"fromDate": "2021-05-27",
"toDate": "2022-12-31",
"name": "StrickHours",
"strictHours": true,
"timeSlots": [
{
"id": "1lkvdZa6",
"productWorkingDateId": "baQkKROA",
"dayOfWeek": "Monday",
"startTime": "09:00:00",
"endTime": "20:00:00",
"duration": "01:00:00",
"quantity": 67,
"usedQuantity": 0,
"active": true,
"deletedAt": null
}
],
"deletedAt": null,
"maxUsedTicketsQuantity": 0,
"errorCode": 0
}
],
"productRegions": [
{
"id": "4lrWZgOd",
"productId": "jpjeneOM",
"regionId": "5bpJKaVE",
"regionName": null
}
],
"productPrices": [
{
"id": "1lon0Aa7",
"productId": "jpjeneOM",
"channelId": "5bpJKaVE",
"fromDate": "2021-08-02T00:00:00",
"toDate": "2022-12-31T00:00:00",
"title": "API",
"remarks": "Test",
"officialPrice": 34,
"currencyId": "5bpJKaVE",
"quantityPerDay": 123,
"autoConfirm": true,
"pricePerPerson": false,
"productPriceTypes": [
{
"id": "xl4WJ7aj",
"productPriceId": "1lon0Aa7",
"productCustomerTypeId": "ZOw36ZOx",
"amount": 12,
"currencyId": "5bpJKaVE",
"currencySymbol": null,
"isOfficial": false,
"productCustomerType": null
}
],
"deletedAt": null
}
]
例子中的productPrices
是一个数组,你没说选哪个,jsonpath的语法是productPrices.*.channelId
,所以你得到的是数组。您可以选择第一个,例如 productPrices.0.channelId
或其他。
我正在测试 API 放心,并尝试使用以下方法从我创建的产品中获取 Id 作为字符串
String productId = response.jsonPath().getString("productPrices.productId");
String channelId = response.jsonPath().getString("productPrices.channelId");
但它返回一个数组
当我打印出这些 ID 时,得到以下输出;
System.out.println("productId is ===> " +productId);
System.out.println("channelId is ===> " +channelId);
输出为
productId is ===>[jpjeneOM]
channelId is ===>[5bpJKaVE]
我的问题是,我只需要将这些 ID 作为字符串获取!!! 请帮我解决这个问题 提前致谢
我有以下负载
{
"id": "jpjeneOM",
"name": "NewProductForTest",
"productTypeId": null,
"active": true,
"shortDescription": "API",
"fullDescription": "API Automation",
"policy": null,
"mostPopular": null,
"longitude": 34.774667,
"latitude": 32.085814,
"calendarColor": "blue",
"address": "Dizengoff Street, Tel Aviv-Yafo",
"cityId": "nlYxZ6az",
"createdAt": "2021-08-06T07:49:14.920615",
"productImages": [
],
"productDocuments": [
],
"productTypes": null,
"productWorkingDates": [
{
"id": "baQkKROA",
"productId": "jpjeneOM",
"fromDate": "2021-05-27",
"toDate": "2022-12-31",
"name": "StrickHours",
"strictHours": true,
"timeSlots": [
{
"id": "1lkvdZa6",
"productWorkingDateId": "baQkKROA",
"dayOfWeek": "Monday",
"startTime": "09:00:00",
"endTime": "20:00:00",
"duration": "01:00:00",
"quantity": 67,
"usedQuantity": 0,
"active": true,
"deletedAt": null
}
],
"deletedAt": null,
"maxUsedTicketsQuantity": 0,
"errorCode": 0
}
],
"productRegions": [
{
"id": "4lrWZgOd",
"productId": "jpjeneOM",
"regionId": "5bpJKaVE",
"regionName": null
}
],
"productPrices": [
{
"id": "1lon0Aa7",
"productId": "jpjeneOM",
"channelId": "5bpJKaVE",
"fromDate": "2021-08-02T00:00:00",
"toDate": "2022-12-31T00:00:00",
"title": "API",
"remarks": "Test",
"officialPrice": 34,
"currencyId": "5bpJKaVE",
"quantityPerDay": 123,
"autoConfirm": true,
"pricePerPerson": false,
"productPriceTypes": [
{
"id": "xl4WJ7aj",
"productPriceId": "1lon0Aa7",
"productCustomerTypeId": "ZOw36ZOx",
"amount": 12,
"currencyId": "5bpJKaVE",
"currencySymbol": null,
"isOfficial": false,
"productCustomerType": null
}
],
"deletedAt": null
}
]
例子中的productPrices
是一个数组,你没说选哪个,jsonpath的语法是productPrices.*.channelId
,所以你得到的是数组。您可以选择第一个,例如 productPrices.0.channelId
或其他。