将 apiDefaults 的值设置为变量
Set value of apiDefaults to a variable
我一直在尝试找到一种方法来从 SQL 数据库中提取数据行,将返回的行格式化为 JSON 格式,并将 post/send 格式化为 JSON 网页 API。我正在使用 VBScript (.Flush) 的 asp JSON 序列化程序将 SQL 数据转换为 JSON。它工作得很好,我有我需要的结构,我也有发送 JSON 格式数据的方法。那么你可能会问什么问题....
问题是我无法将 apiDefaults.flush 发送到网络服务器,它不起作用。如果我发送与硬编码变量相同的数据,它会完美地工作并且 API 获取数据。
让我再解释一下。
这是我使用 apiDefaults.flush 在屏幕上看到的 JSON 输出,格式完全符合我的需要。
{"authentication": { "apiKey": "123456789101112131415" }, "createProperties": [ { "name": "Property 1", "propKey": "6sf3zqq151n2wkah" }, { "name": "Property 2", "propKey": "yuf38zc4cls9hz19" } ] }
但是,我无法将此值存储到变量中。如果我可以简单地执行以下操作,我的问题就会得到解决,但是您不能将 .flush 方法绑定到变量?!?!我不明白为什么,理论上它只是一串文本。
dim myJson = apiDefaults.flush
这段代码是我设置要发送到网络服务器的值的地方,我的变量保存 JSON 字符串
'IF I USE THIS IT WORKS PERFECTLY, IT TAKES MY MANUALLY CREATED VARIABLE/STRING AND SENDS IT
oXMLHttp.send strmultiprop
'THIS IS WHAT I FIGURED I SHOULD BE ABLE TO USE BUT IT IS NOT TREATED LIKE A VARIABLE
oXMLHttp.send apiDefaults.flush
' I TRIED THIS AND THIS WON'T WORK EITHER
oXMLHttp.send myJson
下面是我的实际脚本
<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<!--#include file="JSON_2.0.4.asp"-->
<%
Function QueryToJSON(dbcomm, params)
Dim rs, jsa, aaa, bbb
Set rs = dbcomm.Execute(,params,1)
Set jsa = jsArray()
Do While Not (rs.EOF Or rs.BOF)
Set jsa(Null) = jsObject()
For Each col In rs.Fields
jsa(Null)(col.Name) = col.Value
Next
rs.MoveNext
Loop
Set QueryToJSON = jsa
rs.Close
End Function
strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=LOCALHOST;UID=sa;PWD=********;DATABASE=DB_Site"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
query = "SELECT wce_uid as name, uniqueid as propKey FROM wces_users WHERE Prop_Moved = ?"
CustomerID = "Y" 'Request.QueryString("CustomerID")
arParams = array(CustomerID)
Set cmd = Server.CreateObject("ADODB.Command")
cmd.CommandText = query
Set cmd.ActiveConnection = conn
'
key = "1234567891011121314151678910"
url = "https://www.beds24.com/api/json/createProperties"
'1 PROPERTY WORKING
str1prop = "{""authentication"": { ""apiKey"": ""123456789101112131415"" }, ""createProperties"": [ { ""name"": ""New Test"", ""propKey"": ""NewTest1"" } ] }"
'2 PROPERTY WORKING
strmultiprop = "{""authentication"": { ""apiKey"": ""123456789101112131415"" }, ""createProperties"": [ { ""name"": ""3333"", ""propKey"": ""3333"" }, { ""name"": ""4444"", ""propKey"": ""4444"" } ] }"
set apiDefaults = QueryToJSON(cmd, arParams)
'3 THE FLUSH METHOD --- THIS DOES NOT SET THE VRIABLE TO THE OUTPUT I SEE ON SCREEN
dim myJson = apiDefaults.flush
apiDefaults.flush
conn.Close : Set Conn = Nothing
Dim oXMLHttp
Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
oXMLHttp.open "POST", url,false
oXMLHttp.setRequestHeader "Content-Type", "application/json"
oXMLHttp.send apiDefaults.flush 'THIS IS THE ISSUE LINE USING THIS. if I CHANGE TO strmultiprop NO ISSUES AT ALL.
response.write oXMLHttp.responseText
Set oXMLHttp = Nothing
%>
对此有任何建议都很好。
感谢观看。
@SearchAndResQ 回答了我的问题
"Try oXMLHttp.send apiDefaults.jsString, you need the value in that property"
我一直在尝试找到一种方法来从 SQL 数据库中提取数据行,将返回的行格式化为 JSON 格式,并将 post/send 格式化为 JSON 网页 API。我正在使用 VBScript (.Flush) 的 asp JSON 序列化程序将 SQL 数据转换为 JSON。它工作得很好,我有我需要的结构,我也有发送 JSON 格式数据的方法。那么你可能会问什么问题....
问题是我无法将 apiDefaults.flush 发送到网络服务器,它不起作用。如果我发送与硬编码变量相同的数据,它会完美地工作并且 API 获取数据。
让我再解释一下。
这是我使用 apiDefaults.flush 在屏幕上看到的 JSON 输出,格式完全符合我的需要。
{"authentication": { "apiKey": "123456789101112131415" }, "createProperties": [ { "name": "Property 1", "propKey": "6sf3zqq151n2wkah" }, { "name": "Property 2", "propKey": "yuf38zc4cls9hz19" } ] }
但是,我无法将此值存储到变量中。如果我可以简单地执行以下操作,我的问题就会得到解决,但是您不能将 .flush 方法绑定到变量?!?!我不明白为什么,理论上它只是一串文本。
dim myJson = apiDefaults.flush
这段代码是我设置要发送到网络服务器的值的地方,我的变量保存 JSON 字符串
'IF I USE THIS IT WORKS PERFECTLY, IT TAKES MY MANUALLY CREATED VARIABLE/STRING AND SENDS IT
oXMLHttp.send strmultiprop
'THIS IS WHAT I FIGURED I SHOULD BE ABLE TO USE BUT IT IS NOT TREATED LIKE A VARIABLE
oXMLHttp.send apiDefaults.flush
' I TRIED THIS AND THIS WON'T WORK EITHER
oXMLHttp.send myJson
下面是我的实际脚本
<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<!--#include file="JSON_2.0.4.asp"-->
<%
Function QueryToJSON(dbcomm, params)
Dim rs, jsa, aaa, bbb
Set rs = dbcomm.Execute(,params,1)
Set jsa = jsArray()
Do While Not (rs.EOF Or rs.BOF)
Set jsa(Null) = jsObject()
For Each col In rs.Fields
jsa(Null)(col.Name) = col.Value
Next
rs.MoveNext
Loop
Set QueryToJSON = jsa
rs.Close
End Function
strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=LOCALHOST;UID=sa;PWD=********;DATABASE=DB_Site"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
query = "SELECT wce_uid as name, uniqueid as propKey FROM wces_users WHERE Prop_Moved = ?"
CustomerID = "Y" 'Request.QueryString("CustomerID")
arParams = array(CustomerID)
Set cmd = Server.CreateObject("ADODB.Command")
cmd.CommandText = query
Set cmd.ActiveConnection = conn
'
key = "1234567891011121314151678910"
url = "https://www.beds24.com/api/json/createProperties"
'1 PROPERTY WORKING
str1prop = "{""authentication"": { ""apiKey"": ""123456789101112131415"" }, ""createProperties"": [ { ""name"": ""New Test"", ""propKey"": ""NewTest1"" } ] }"
'2 PROPERTY WORKING
strmultiprop = "{""authentication"": { ""apiKey"": ""123456789101112131415"" }, ""createProperties"": [ { ""name"": ""3333"", ""propKey"": ""3333"" }, { ""name"": ""4444"", ""propKey"": ""4444"" } ] }"
set apiDefaults = QueryToJSON(cmd, arParams)
'3 THE FLUSH METHOD --- THIS DOES NOT SET THE VRIABLE TO THE OUTPUT I SEE ON SCREEN
dim myJson = apiDefaults.flush
apiDefaults.flush
conn.Close : Set Conn = Nothing
Dim oXMLHttp
Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
oXMLHttp.open "POST", url,false
oXMLHttp.setRequestHeader "Content-Type", "application/json"
oXMLHttp.send apiDefaults.flush 'THIS IS THE ISSUE LINE USING THIS. if I CHANGE TO strmultiprop NO ISSUES AT ALL.
response.write oXMLHttp.responseText
Set oXMLHttp = Nothing
%>
对此有任何建议都很好。
感谢观看。
@SearchAndResQ 回答了我的问题
"Try oXMLHttp.send apiDefaults.jsString, you need the value in that property"