-1

我有一个工作任务,使用 Web 服务,在基于 Classic Asp 的网站和基于 android 平台的应用程序之间进行通信,使用参数 Date 创建函数,该函数提供来自 bd 的数据,我不知道如何继续,你能给我一个例子或教程吗?

4

1 回答 1

2

您最简单的选择是像这样生成 json(可以很容易地被 android 端使用):

ASP“服务”

<!-- 
this is one example of a library of json helpers that you can use. 
You can get it from this page
http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/
http://www.webdevbros.net/wp-content/uploads/2008/07/json151.zip
save the downloaded json.asp file in the same folder as your .asp 
-->

<!--#include file="json.asp" -->

<%
    REM 1. Create and populate ADO Recordset from database
    REM   Note: I am providing just an example and you might 
    REM   ant to look into using a more appropriate command type 
    REM   or cursor type when populating your recordset        

    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "put your connection string here"
    Set cmd = Server.CreateObject("ADODB.Command")
    cmd.CommandType = adCmdText 'note must have this constant defined in scope'
    Set cmdTemp.ActiveConnection = conn

    cmd.CommandText = "put your SQL here; be careful to protect against SQL injections" 

    Set rs = Server.CreateObject("ADODB.Recordset")

    rs.Open cmd, ,adOpenForwardOnly,adLockReadOnly 'note make sure these constants are defined in scope'

    REM 2. Prepare json
    Dim jsonObject

    Set jsonObject = New JSON   'JSON class is in the include file json.asp'
    jsonResult = jsonObject.toJSON(Empty, rs, False) 'You may have to play with the parameters here, if the way json is formatted does not suit you'
                                                   'check the documentation of json.asp library'

    REM 3. stream json to client
    Response.ContentType = "application/json" 
    Response.Write jsonResult
%>

您可以找到更多有助于将值或结构格式化为 JSON 的库:只需在 SO 或 google 上搜索“classic ASP”+ JSON。这是一个采用 vbscript/ASP 结构并以 JSON 格式输出它们的库。查看 SQL 示例。

检查这个SO 线程以获得更多“经典”的 ASP 和 JSON

于 2013-03-29T03:30:21.310 回答