想用ASP+MSSQL做后台,但不知道如何response.Write 到前台小程序端,让小程序能够渲染的格式JSON,
有没有师傅,请教一下,找了很多资料都不行。
非常感谢!
asp代码如下:
<%@LANGUAGE=“VBSCRIPT” CODEPAGE=“65001”%>
<%response.ContentType = " text/json " %>
<!–#include file=“json.asp”–>
<!–#include file=“Connections/xfydata.asp” -->
<%
Dim SITEds
Dim SITEds_cmd
Dim SITEds_numRows
Set SITEds_cmd = Server.CreateObject (“ADODB.Command”)
SITEds_cmd.ActiveConnection = MM_xfydata_STRING
SITEds_cmd.CommandText = “SELECT site_no as value,site_desc as name,‘false’ as checked FROM dbo.产品类”
SITEds_cmd.Prepared = true
Set SITEds = SITEds_cmd.Execute
jsonStr = ""
rows = “”
Dim i,json_rows,json_ret,arr_rows
Dim myArray(3,3)
Set jsonObj=New json
jsonObj.toResponse=False
Set json_ret = server.createobject(“scripting.dictionary”)
Dim line1
line1=0
While Not (SITEds.EOF Or SITEds.BOF)
i=0
For Each col In SITEds.Fields
myArray(line1,i)=col.value
i=i+1
Next
line1=line1+1
SITEds.MoveNext
Wend
'json_ret.Add “total”,line1
json_ret.Add “rows”,myArray
jsonStr = jsonObj.toJSON(Empty,json_ret,False)
response.Write jsonStr
SITEds_numRows = 0
%>
<%
SITEds.Close()
Set SITEds = Nothing
%>
在小程序端输出结果:
data:
rows:(16)[“A”,“B”,"","",“测试账号”,“美的风扇”…]
我想要的结果是:
SETDATA如下格式
data: {
items: [
{
value: 'CHN',
name: '中国',
checked: 'true'
}
]
},
再次感谢