I need to query the database, and it returns a JSON.
I tried using JSON for ASP from Google, but it gave some errors, so I decided to do it manually:
<!--#include file="conexao.asp"-->
<%
medico = replace(request("medico"),"'","")
crm = replace(request("crm"),"'","")
sql = "SELECT nome_pro, crm FROM medicos WHERE nome LIKE UPPER('%" & medico & "%') "
set rs = server.createobject("adodb.recordset")
rs.cursorlocation = 3
rs.open sql,conexao
response.write("[")
If Not RS.EOF Then
Do
response.write("{")
for each x in rs.fields
response.write("'" & x.name & "'")
response.write(":")
response.write("'" & x.value & "'")
response.write(",")
next
response.write("}")
response.write(",")
RS.MoveNext()
Loop Until RS.EOF
End If
response.write("]")
%>
The problem I'm having is that when it prints the JSON, it leaves the last comma, like this:
'PEDRO', 'CRM': '000000',}, {'PRIVATE_NAME': 'PEDRO', 'PEDRO', ' , 'CRM': '111111',},]I've never used ASP, I'm using it for the first time to generate this JSON, and I wanted to know if you have any method of not printing this last comma.
And also wanted to know if you have how to make the:
response.write("'" & x.name & "'")
Print double quotes instead of single print.