如何在Rest Assured中提取带有键点的JSON响应

huangapple go评论79阅读模式
英文:

How to extract json Response in rest assured with points in key

问题

要从第一个响应中提取状态,你只需使用 one.responsetwo.response

对于第二个响应,如果你想提取相同的值(而不更改键),可以这样做:

  • 对于 "something.one.txt",你可以使用 something.one.txt.response
  • 对于 "somethinganother.two.txt",你可以使用 somethinganother.two.txt.response
英文:

To extract status form this response in rest assured i just need to use one.response or two.response

{
"one": {
    "status": "SUCCESSFUL",
    "fileNum": "1"
},
"two": {
    "status": "SUCCESSFUL",
    "fileNum": "2"
}}

But how can I extract the same value (without changing key) if i have such response:

{
"something.one.txt": {
    "status": "SUCCESSFUL",
    "fileNum": "1"
},
"somethinganother.two.txt": {
    "status": "SUCCESSFUL",
    "fileNum": "2"
}}

答案1

得分: 0

你需要对键进行转义:

response.jsonPath().getString("'something.one.txt'.status") // 将返回 "SUCCESSFUL"
英文:

You need to escape the key:

response.jsonPath().getString("'something.one.txt'.status") // Will return "SUCCESSFUL"

huangapple
  • 本文由 发表于 2020年9月16日 18:41:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63918290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定