如何从JSON文件中获取变量的值?

如何从JSON文件中获取变量的值?,json,vbscript,Json,Vbscript,当我运行量角器测试用例时,我得到了以下测试用例结果的JSON响应,它被存储在一个文件中,名为combined.JSON 案例1:对于通过的测试案例: {"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria", "passed":true, "os":"XP", "browser": chrome } {"

当我运行量角器测试用例时,我得到了以下测试用例结果的JSON响应,它被存储在一个文件中,名为
combined.JSON

案例1:对于通过的测试案例:

{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":true,
"os":"XP",
"browser": chrome
}
{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":false,
"os":"XP",
"browser": chrome
}
案例2:对于失败的测试案例:

{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":true,
"os":"XP",
"browser": chrome
}
{"description":"tests the case when the login was successful|E2E test Login and search users with different search criteria",
"passed":false,
"os":"XP",
"browser": chrome
}
在上述情况下,测试结果存储在
passed
JSON对象中


我正在HPALM中编写VAPI测试用例,为此我需要通过测试用例状态。我希望将
的值传递给变量。

我认为VBScript没有JSON解析器,因此您必须自己解析文件。由于您有一个非常简单的场景(提取特定键的值),使用正则表达式应该可以,但是:

Set fso = CreateObject("Scripting.FileSystemObject")

json = fso.OpenTextFile("C:\path\to\combined.json").ReadAll

Set re = New RegExp
re.Pattern = """passed"":(true|false),"
re.IgnoreCase = True

For Each m In re.Execute(json)
  passed = CBool(m.SubMatches(0))
Next

谢谢你的回复。在VAPI测试用例中,我们已经合并了您的(正是上面的)代码,并在您的代码之后添加了下面的行。CurrentRun.Status=已通过。现在,每个传递的变量的值都是failed。你能帮我们弄清楚确切的情况吗。谢谢@Durgesh在将
传递的
赋值给
CurrentRun.Status
MsgBox传递的
)之前,它有什么值?
CurrentRun.Status
期望的数据类型是什么?我的示例代码将字符串转换为布尔值。我误解了这一点。现在我可以应用这个逻辑了。谢谢你的帮助。