如何使用VBScript或批处理文件从JSON文件下载和获取值?

如何使用VBScript或批处理文件从JSON文件下载和获取值?,json,batch-file,vbscript,Json,Batch File,Vbscript,这是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.Ex

这是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
但我有一个JSON文件,看起来像这样,它是在线的

["AA-BB-CC-MAKE-SAME.json","SS-ED-SIXSIX-TENSE.json","FF-EE-EE-EE-WW.json","ZS-WE-AS-FOUR-MINE.json","DD-RF-LATERS-LATER.json","FG-ER-DC-ED-FG.json"]

如何下载此JSON文件并使用VBScript或批处理文件获取五个变量的值?

以下是从internet下载JSON并解析它的示例:

Dim http,URL
URL = "http://ip-api.com/json/"
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",URL,False
http.send
strJson = http.responseText

Set j = ParseJson(strJson)
Result = "IP =" & j.query & vbCrlf &_
"ISP = "& j.isp & vbCrlf &_
"Country = "& j.country & vbCrlf &_
"TimeZone = "& j.timezone

Wscript.echo Result
'--------------------------------------------------------
Function ParseJson(strJson)
    Set html = CreateObject("htmlfile")
    Set window = html.parentWindow
    window.execScript "var json = " & strJson, "JScript"
    Set ParseJson = window.json
End Function
'--------------------------------------------------------
您可以尝试使用以下代码:

Dim http,URL
URL = "https://privateURL/jsonfile/"
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET",URL,False
http.send
strJson = http.responseText
Result = Extract(strJson,"(\x22(.*)\x22)")
Arr = Split(Result,",")
For each Item in Arr
    wscript.echo Item
Next
'******************************************
Function Extract(Data,Pattern)
   Dim oRE,oMatches,Match,Line
   set oRE = New RegExp
   oRE.IgnoreCase = True
   oRE.Global = True
   oRE.Pattern = Pattern
   set oMatches = oRE.Execute(Data)
   If not isEmpty(oMatches) then
       For Each Match in oMatches  
           Line = Line & Trim(Match.Value) & vbCrlf
       Next
       Extract = Line
   End if
End Function
'******************************************

检查这个-这个-考虑使用PopeS壳。您的生活将变得更加轻松。我在第9行char 1中得到了这个错误,对象不支持这个属性或方法:“j.query”。密码800A01B6@CodenameK您应该向我提供json文件的真实链接,以尝试正确解析它,在我的示例中,它只适用于脚本中的链接!你拿到链接了吗?它能用。由于链接是个人的,您能否更改答案中的链接?@CodenameK Done;