asp将数据库数据转换成JSON格式
2013-09-11 18:10
561 查看
asp从数据库中读取数据,以JSON形式输出,作为Android 的WebService
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp" -->
<%
response.Charset = "gb2312"
Dim nPageSize,strCatID,strCatName,strInfoView,strInfoFile,nPageCount
strCatID=request("ChannelID")
nPageSize=request("PageSize")
If not Isnumeric(strCatID) Then
strCatID=0
End If
If not Isnumeric(nPageSize) Then
nPageSize=0
End If
If strCatID<=0 Then
Response.Write "参数错误!"
Response.End
End If
If nPageSize<=0 Then
Response.Write "参数错误!"
Response.End
End If
cmdQuery.CommandText = "select top "&nPageSize&" nid,title,source,digest,ptime from t_news where cid='"&strCatID&"' order by nid desc"
Set rstCat=cmdQuery.Execute
If not rstCat.Eof Then
response.Write "{'ret':0,'data':{'newslist':["
for i=1 to nPageSize
response.Write "{"
response.Write "'title':'"&rstCat("title")&"',"
Set cmdQuery2=Server.CreateObject("ADODB.Command")
Set cmdQuery2.ActiveConnection = cnnMyedu123
cmdQuery2.CommandType=1
cmdQuery2.CommandText = "select * from ViewCommentCount where nid="&rstCat("nid")
Set rstCount=cmdQuery2.Execute
if not rstCount.eof then
response.Write "'commentcount':"&rstCount("commentcount")&","
else
response.Write "'commentcount':0,"
end if
set rstCount = nothing
set cmdQuery2 = nothing
response.Write "'source':'"&rstCat("source")&"',"
response.Write "'nid':"&rstCat("nid")&","
response.Write "'digest':'"&rstCat("digest")&"',"
response.Write "'ptime':'"&rstCat("ptime")&"'"
if i = nPageSize-1 then
response.Write "}"
else
response.Write "},"
end if
rstCat.movenext
if rstCat.eof then exit for end if
next
response.Write "],"
response.Write "'totalnum':"&nPageSize&""
response.Write "},"
response.Write "'msg':'ok'"
response.Write "}"
Else
Response.Write "栏目不存在!"
Response.End
End If
Set rstCat=Nothing
set cmdQuery = nothing
%>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp" -->
<%
response.Charset = "gb2312"
Dim nPageSize,strCatID,strCatName,strInfoView,strInfoFile,nPageCount
strCatID=request("ChannelID")
nPageSize=request("PageSize")
If not Isnumeric(strCatID) Then
strCatID=0
End If
If not Isnumeric(nPageSize) Then
nPageSize=0
End If
If strCatID<=0 Then
Response.Write "参数错误!"
Response.End
End If
If nPageSize<=0 Then
Response.Write "参数错误!"
Response.End
End If
cmdQuery.CommandText = "select top "&nPageSize&" nid,title,source,digest,ptime from t_news where cid='"&strCatID&"' order by nid desc"
Set rstCat=cmdQuery.Execute
If not rstCat.Eof Then
response.Write "{'ret':0,'data':{'newslist':["
for i=1 to nPageSize
response.Write "{"
response.Write "'title':'"&rstCat("title")&"',"
Set cmdQuery2=Server.CreateObject("ADODB.Command")
Set cmdQuery2.ActiveConnection = cnnMyedu123
cmdQuery2.CommandType=1
cmdQuery2.CommandText = "select * from ViewCommentCount where nid="&rstCat("nid")
Set rstCount=cmdQuery2.Execute
if not rstCount.eof then
response.Write "'commentcount':"&rstCount("commentcount")&","
else
response.Write "'commentcount':0,"
end if
set rstCount = nothing
set cmdQuery2 = nothing
response.Write "'source':'"&rstCat("source")&"',"
response.Write "'nid':"&rstCat("nid")&","
response.Write "'digest':'"&rstCat("digest")&"',"
response.Write "'ptime':'"&rstCat("ptime")&"'"
if i = nPageSize-1 then
response.Write "}"
else
response.Write "},"
end if
rstCat.movenext
if rstCat.eof then exit for end if
next
response.Write "],"
response.Write "'totalnum':"&nPageSize&""
response.Write "},"
response.Write "'msg':'ok'"
response.Write "}"
Else
Response.Write "栏目不存在!"
Response.End
End If
Set rstCat=Nothing
set cmdQuery = nothing
%>
相关文章推荐
- 从数据库取到数据转换json后,时间格式带上T的解决办法
- asp.net数据库生成LigerUi树Tree结构Json格式数据(有点绕,附基本源代码)
- 【原创】c#讲数据库数据转换为json格式(使用extjs,easyui中的datagrid)
- c#将数据库数据转换为json格式(使用extjs,easyui中的datagrid)
- Asp.net/Jquery/JS中各种数据转换为【JSON数据格式】的类!(相当好,转)
- php将从数据库中获得的数据转换成json格式并输出
- 从数据库取到数据转换json后,时间格式带上T的解决办法
- ASP.NET DataSet查询结果转换为JSON格式数据
- php从数据库中取数据转换为json格式
- 将数据库中的数据转换成json格式
- 关于Java语言的eclipse读取数据库,并将数据转换成JSON格式输出
- 省市县从数据库读出来的list数据转换成json格式的数据
- php将从数据库中获得的数据转换成json格式并输出的方法
- django-将数据库数据转换成JSON格式(ORM和SQL两种情况)
- 数据库中查询出来的数据转换成json格式
- json格式数据,将数据库中查询的结果转换为json, 然后调用接口的方式返回json(方式一)
- json格式数据 ,将数据库中查询的结果转换为json(方式2)
- 使用Javascript/jQuery将javascript对象转换为json格式数据
- fastJson数据格式转换(二)SerializerFeature属性再解
- 数据库记录转换成json格式