使用返回 null 的 JSONPath 从 JSON 获取值

问题描述 投票:0回答:1

新手:我正在尝试从 POST 调用的响应正文中获取 id。 POST 成功,但当我尝试获取 id 并记录它时,它返回 null。我想我只是错过了一件小事,但是是的,需要你的帮助。

  ${response_body}    Decode Bytes To String    ${response.content}    encoding=utf-8     
  Set Test Variable    ${response_body}     
  Log    ${response_body}     
  ${id}    Get Value From Json    ${response_body}    id     
  Log    ${id}

实际响应正文只是:

    {
        "id": "546e0c4d-b810-49e6-a674-0d0f812bb790"
    }

以下是我在报告中得到的内容:

report that shows id is empty

没有错误,只有空白值

我尝试将response_body设置为整体id,但当我调用${id}时,我得到“id”=“xxxxx ...”,所以是的,我只需要该值

python python-3.x rest automated-tests robotframework
1个回答
0
投票

你的问题是

${response_body}
是一个字符串,而不是一个 JSON。您必须使用“Convert String To Json
to convert it to JSON before
Get Value From Json”有效。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.