英文:
How to get the key value from response where the position of the key value pair are changing on each request
问题
有一个独特的问题,当我一遍又一遍地请求相同的API时,我得到的响应是相同的,但响应的键值对的值不断变化,值保持不变。
第一个请求的响应:
{
"fields": {
"customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "测试日程安排",
"test_additional_history": "(0010,21B0)",
"test_mother_birthname": "(0010,1060)",
"customfield-73ee5b7f-5cfb-4cbb-ab09-69583de4b9cc": "您是否想要请求加急中央审查以确认进展?",
"test_current_location": "(0038,0300)",
"test_size": "(0010,1020)",
"customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "这是基线测试吗?",
"modality": "(0008,0060)",
"date": "(0008,0020)",
"customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "受试者编号",
"test_name": "(0010,0010)",
"customfield-f049af7b-a550-45dc-8bae-abc27797518f": "备注",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208": "试验测试名称",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-26918767-1b73-413c-835d-ed204f1a3297": "测试手臂",
"user_mother_birthname": "(0010,1060)",
"customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd": "测试ID",
"user_birth_time": "(0010,0032)",
"customfield-8de944cd-ad93-490a-b34d-f8d248a70997": "测试开始日期",
"user_address": "(0010,1040)",
"customfield-5c0bb293-3f4b-42b5-aa49-b121d621a3dd": "随机化日期",
"user_description": "(0008,1030)",
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "试验项目tims",
"user_record_locator": "(0010,1090)"
},
"status": "OK",
"defaults": {
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "PERF_TEST00004"
}
}
第二个请求的响应:
{
"status": "OK",
"defaults": {
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "PERF_TEST00004"
},
"fields": {
"customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "受试者编号",
"test_additional_history": "(0010,21B0)",
"test_mother_birthname": "(0010,1060)",
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "试验项目tims",
"test_current_location": "(0038,0300)",
"test_size": "(0010,1020)",
"customfield-26918767-1b73-413c-835d-ed204f1a3297": "测试手臂",
"modality": "(0008,0060)",
"date": "(0008,0020)",
"customfield-8de944cd-ad93-490a-b34d-f8d248a70997": "测试开始日期",
"test_name": "(0010,0010)",
"customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208": "试验测试名称",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-5c0bb293-3f4b-42b5-aa49-b121d621a3dd": "随机化日期",
"user_mother_birthname": "(0010,1060)",
"customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "这是基线测试吗?",
"user_birth_time": "(0010,0032)",
"customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd": "测试ID",
"user_address": "(0010,1040)",
"customfield-f049af7b-a550-45dc-8bae-abc27797518f": "备注",
"user_description": "(0008,1030)",
"customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "测试日程安排",
"user_record_locator": "(0010,1090)",
"customfield-73ee5b7f-5cfb-4cbb-ab09-69583de4b9cc": "您是否想要请求加急中央审查以确认进展?"
}
}
两个响应是相同的,只是值的位置改变了。我想获取特定值的键。
例如:
1. "customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "测试日程安排"
2. "customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "这是基线测试吗?"
3. "customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "受试者编号"
4. "customfield-f049af7b
<details>
<summary>英文:</summary>
Have a unique problem, when I request the same api again and again I am getting the same response but the key-value pair of the response are keep on changing values are remain same.
Response 1 on first request:
{
"fields": {
"customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "Test Schedule",
"test_additional_history": "(0010,21B0)",
"test_mother_birthname": "(0010,1060)",
"customfield-73ee5b7f-5cfb-4cbb-ab09-69583de4b9cc": "Would you like to request an expedited central review to confirm progression?",
"test_current_location": "(0038,0300)",
"test_size": "(0010,1020)",
"customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "Is this a baseline test?",
"modality": "(0008,0060)",
"date": "(0008,0020)",
"customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "Subject Number",
"test_name": "(0010,0010)",
"customfield-f049af7b-a550-45dc-8bae-abc27797518f": "Comments",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208": "trial_test_name",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-26918767-1b73-413c-835d-ed204f1a3297": "Test Arm",
"user_mother_birthname": "(0010,1060)",
"customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd": "Test ID",
"user_birth_time": "(0010,0032)",
"customfield-8de944cd-ad93-490a-b34d-f8d248a70997": "Test Start Date",
"user_address": "(0010,1040)",
"customfield-5c0bb293-3f4b-42b5-aa49-b121d621a3dd": "Randomization Date",
"user_description": "(0008,1030)",
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "trial_project_tims",
"user_record_locator": "(0010,1090)"
},
"status": "OK",
"defaults": {
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "PERF_TEST00004"
}
}
Response 2 on second request:
{
"status": "OK",
"defaults": {
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "PERF_TEST00004"
},
"fields": {
"customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "Subject Number",
"test_additional_history": "(0010,21B0)",
"test_mother_birthname": "(0010,1060)",
"customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "trial_project_tims",
"test_current_location": "(0038,0300)",
"test_size": "(0010,1020)",
"customfield-26918767-1b73-413c-835d-ed204f1a3297": "Test Arm",
"modality": "(0008,0060)",
"date": "(0008,0020)",
"customfield-8de944cd-ad93-490a-b34d-f8d248a70997": "Test Start Date",
"test_name": "(0010,0010)",
"customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208": "trial_test_name",
"user_occupation": "(0010,2180)",
"user_birthname": "(0010,1005)",
"user_size": "(0010,1020)",
"customfield-5c0bb293-3f4b-42b5-aa49-b121d621a3dd": "Randomization Date",
"user_mother_birthname": "(0010,1060)",
"customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "Is this a baseline test?",
"user_birth_time": "(0010,0032)",
"customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd": "Test ID",
"user_address": "(0010,1040)",
"customfield-f049af7b-a550-45dc-8bae-abc27797518f": "Comments",
"user_description": "(0008,1030)",
"customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "Test Schedule",
"user_record_locator": "(0010,1090)",
"customfield-73ee5b7f-5cfb-4cbb-ab09-69583de4b9cc": "Would you like to request an expedited central review to confirm progression?"
}
}
Both the response are identical only the value's place are changed. I want to fetch the `key` of very specific value.
example:
1. "customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab": "Test Schedule"
2. "customfield-6844b23b-cff0-44b0-b2af-5eda668dc729": "Is this a baseline test?"
3. "customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314": "Subject Number"
4. "customfield-f049af7b-a550-45dc-8bae-abc27797518f": "Comments"
5. "customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208": "trial_test_name"
6. "customfield-26918767-1b73-413c-835d-ed204f1a3297": "Test Arm"
7. "customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd": "Test ID"
8. "customfield-d378e755-6da9-4ba5-a8ef-41026272adda": "trial_project_tims"
Want to fetch all the key value which is,
customfield-4b7c5fb0-20de-4c4f-aecf-892b585855ab
customfield-6844b23b-cff0-44b0-b2af-5eda668dc729
customfield-d52ba358-07c1-428e-a345-b8bcb8d9b314
customfield-f049af7b-a550-45dc-8bae-abc27797518f
customfield-5701c632-33a1-4e67-9c34-c0bbf3a82208
customfield-26918767-1b73-413c-835d-ed204f1a3297
customfield-a5363a01-b8b2-4da2-acfe-bbc2316dbbdd
customfield-d378e755-6da9-4ba5-a8ef-41026272adda
Used regular expression,
for example for getting the subject number I used
regex: `"date":"(.*?)","(.*?)":"Subject Number"`
$1$
2
Worked first time but failing second time as the position changed. Is there any way like using `JSON Extractor` or any other with condition to find the keys based upon the value as value will be constant all the time ?
</details>
# 答案1
**得分**: 1
根据您的输出,以下是可以解决您的问题的正则表达式:
所以根据您的说法,这些值是常量,您需要相应的键,那么这些表达式将解决您的问题:
\s*"([^"]*)":?\s*"测试计划"
\s*"([^"]*)":?\s*"这是一个
\s*"([^"]*)":?\s*"受试者编号"
\s*"([^"]*)":?\s*"评论"
\s*"([^"]*)":?\s*"试验名称"
\s*"([^"]*)":?\s*"测试组"
\s*"([^"]*)":?\s*"测试ID"
\s*"([^"]*)":?\s*"试验项目Tims"
<details>
<summary>英文:</summary>
According to your output these are the regular expression which should solve your problem,
So according to you the values are constant and you need the corresponding keys then these expression will solve your problem,
\s*"([^"]*)":?\s*"Test Schedule"
\s*"([^"]*)":?\s*"Is this a
\s*"([^"]*)":?\s*"Subject Number"
\s*"([^"]*)":?\s*"Comments"
\s*"([^"]*)":?\s*"trial_test_name"
\s*"([^"]*)":?\s*"Test Arm"
\s*"([^"]*)":?\s*"Test ID"
\s*"([^"]*)":?\s*"trial_project_tims"
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论