I’m trying to serialize a SQL query in ASP to a json object like this:
[[“name1″,”phone1″,”email1″,”address1”],[“name2″,”phone2″,”email2″,”address2”]]
I’ve made two loops to go through the columns and the rows of the db and this is how i got so far;
<!--#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)
What am i getting wrong here, I’ve tried to change every value possible.
The result gives me just the last row of the table(like the following) of course i would like to retrive every row from the table.
Thank you in advance for any possible answer.
[“La Musical Fashion”,”214478457″,”musical@fashion.pt”,”Av. Quinta Grande, 8 R/C Esq.”]
Need to build an
Array of ArrayslikeArray(Array(col1,col2,col3), Array(col1,col2,col3))to get desired result obtained throughtoJSON.You can do it with something like below.