我正在尝试将 ASP 中的 SQL 查询序列化为这样的 json 对象:
[["name1","phone1","email1","address1"],["name2","phone2","email2","address2"]]
我做了两个循环来遍历数据库的列和行,这就是我到目前为止的方式;
<!--#include file="JSON_2.0.4.asp"-->
SQL = "SELECT name, phone, email, address FROM clients"
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.Open "Provider=sqloledb;SERVER=localhost;DATABASE=mydatabase;UID=;PWD=1234;"
Recordset.Open SQL,Connection
rsArray = Recordset.getRows()
ReDim arrObj(UBound(rsArray, 2) - 1)
Dim i, j
For i = 1 To UBound(rsArray, 2)
ReDim arrProp(UBound(rsArray, 1))
For j = 0 To UBound(rsArray, 1)
arrProp(j) = rsArray(j, i)
Next
Next
Response.Write toJSON(arrProp)
我在这里做错了什么,我试图改变每一个可能的值。结果只给了我表格的最后一行(如下所示),当然我想从表格中检索每一行。提前感谢您提供任何可能的答案。
[“La Musical Fashion”,“214478457”,“musical@fashion.pt”,“Av. Quinta Grande,8 R/C Esq.”]