2
I need to make a query in the database, and returns a JSON.
I tried using JSON for ASP from Google, but there were 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 he prints the JSON, the last comma comes out, like this:
[{'NOME_PRO':'ALCINDO','CRM':'000000',},{'NOME_PRO':'PEDRO','CRM':'000000',},{'NOME_PRO':'PEDRO','CRM':'111111',},]
I never used ASP, I’m using for the first time to generate this JSON, and I was wondering if there are any ways to not print this last comma.
And I was also wondering if there’s any way to get:
response.write("'" & x.name & "'")
Print double quotes instead of single print.