假设我们有以下JSON响应:
{
"abcd1234": {
"foo": "bar"
}
}
如何在响应解析的正文值中访问“bar”?在回复中,"abcd1234"
可以是任何内容。但我们想要对象中的第一个键(在JavaScript中,这将是Object.keys(res)[0]
)。
答案 0 :(得分:1)
Paw可以轻松解析JSON(和XML)响应并通过其密钥路径访问子字段。
本文档文章可能有所帮助:https://paw.cloud/docs/advanced/reuse-values-from-previous-responses
插入Response Parsed Body动态值
设置输入请求并提取所需的值
在您的示例中,关键路径为:
print ("Python calculator")
print ("""
Select an operation below
1: Add
2: Sub
3: Mult
4: Div
""")
def add(x, y, z):
return x + y + z
def sub(x, y, z):
return x - y - z
def mult(x, y, z):
return x * y * z
def div(x, y, z):
return x / y / z
Operation = input ("Enter Operation Number")
Number1 = int(input ("Enter Your First Number"))
Number2 = int(input ("Enter your Second Number"))
Number3 = (0)
More = input ("Do you have more numbers? (Yes or No)")
if More == "yes" or More == "Yes":
Number3 =int(input ("What is your other number?"))
print ("calculating")
else:
print ("calculating")
if Operation == '1':
print(add(Number1,Number2,Number3))
elif Operation == '2':
print(sub(Number1,Number2,Number3))
elif Operation == '3'and More != "Yes":
Number4 = 1
print(mult(Number1,Number2,Number4 ))
elif Operation == '3':
print(mult(Number1,Number2,Number3 ))
elif Operation == '4'and More != "Yes":
Number4 = 1
print(div(Number1,Number2,Number4 ))
elif Operation == '4':
print(div(Number1,Number2,Number3 ))
else:
print("Invalid inputs")
尽管如此,您似乎需要在不知道密钥的情况下访问路径。如果是这样,一种方法是使用JavaScript代码段来实现您想要的行为。
在任何字段上,您都可以右键单击并选择扩展程序> JS脚本。
这是一个可能符合您需求的代码段:
abcd1234.foo